Is there any way to have the new node created without any user input?

So basically user would just click add to cart and then be taken to checkout, but behind the scenes a new node was created.

Comments

millenniumtree’s picture

I had this requirement as well.
I used a form_alter hook to print a bit of javascript to auto-submit the form.
The CSS prevents the form from being seen momentarily before it auto-submits.

function YOUR_MODULE_form_alter(&$form, &$form_state, $form_id) {
	switch($form_id) {
		case 'YOUR_CONTENT_TYPE_node_form':
			$form['autosubmit'] = array( '#value' => '<style type="text/css">body{display:none !important;}</style><script type="text/javascript">$(document).ready(function() { $("#node-form").submit(); });</script>', );
	}
}

My module was a heck of a lot more complicated than that, because I had some logic involving attributes, field access rules and an image field that pulls from the user's profile, but that should get you going.

peterx’s picture

I have a need to completely skip the form before purchase. I tried the option
Redirect customers to the node add form when they click add to cart buttons of node checkout associated products.
When the option is off, the node is not created. I suspect it is because some fields are required and are not filled out.

stewart.adam’s picture

You can use node_save() to programatically create nodes (example here), but keep in mind that it will do only that - if you're wanting to integrate this with node checkout or implement your own solution, you'll need to relate the cart item to the node manually.