Embedding CCK content type create form in your page

To embed CCK node create form into page/node in Drupal 6.x or other template file use the following code. Replace "store_review" with the machine-readable name of your content type (for example, Story nodes are "story" and "Store Reviews" are "store_review").


$node = new stdClass();
$node->type = 'store_review';
module_load_include('inc', 'node', 'node.pages');
$output = drupal_get_form('store_review_node_form', $node);

I spent several hours looking for solution. Here is the link to original source of the solution: http://drupal.org/node/261495

Alternative

  if(!function_exists("node_object_prepare")) {
    include_once(drupal_get_path('module', 'node') . '/node.pages.inc');
  }
  print node_add('store_review');

It doesn't work

arebos - July 12, 2009 - 11:06

I have a custom content-type name 'pembaca' to implement those technic. So, I copy node.tpl.php and then rename to node-pembaca.tpl.php.
Embed above code and make little change to:

$node = new stdClass();
$node->type = 'pembaca';
module_load_include('inc', 'node', 'node.pages');
$output = drupal_get_form('pembaca_node_form', $node);

Then it doesn't work.
Can you help me? What's wrong?

It doesn't work

arebos - July 12, 2009 - 11:07

I have a custom content-type name 'pembaca' to implement those technic. So, I copy node.tpl.php and then rename to node-pembaca.tpl.php.
Embed above code and make little change to:

$node = new stdClass();
$node->type = 'pembaca';
module_load_include('inc', 'node', 'node.pages');
$output = drupal_get_form('pembaca_node_form', $node);

Then it doesn't work.
Can you help me? What's wrong?

You have to print the output

victorkane - August 14, 2009 - 11:15

The $output variable contains the rendering, but for it to actually appear on the page, you have to "print" it. Did you add a line somewhere similar to:

print $output;

 
 

Drupal is a registered trademark of Dries Buytaert.