I am trying to get form that is used in content type template in template.php. I am creating node collections with EntityFieldQuery, and I am pulling field values of content type without problem.

But i need to access form, and add it to html stream that i create in template.php

In content type i can do

print render($content['add_to_cart']);

To get form out.

But now in template.php i need that form for specific nodes (im pulling them with EntityFieldQuery) as html, so i can include it to rest of the stream and send the data in variable, and simply output it where i need it (content type page.)


2 Answers 2


I'm not sure, if this is what you are looking. But if you want to embed a node-add form you could use the following code.

$node = new stdClass();
$node->type = 'machine_name_of_your_content_type';
module_load_include('inc', 'node', 'node.pages');
$output = drupal_get_form('machine_name_of_your_content_type_node_form', $node);
print $output;
  • I did not test it, but it seems like correct answer, as it gets all the form in $output variable (i hope :) )
    – NenadP
    Commented Sep 6, 2012 at 16:41

Thanks to aerozeppelin, i implemented it this way:

in template.php ($node is fetched via EntityFieldQuery)

$add_to_cart = array( '#theme' => 'uc_product_add_to_cart',
'#form' => drupal_get_form('uc_product_add_to_cart_form_' . $node->nid, $node), );
$cart_form = drupal_render($add_to_cart);

where $cart_form contains html data form, that i included in my data stream!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.