Community Documentation

Embedding CCK content type create form in your page

Last updated August 26, 2009. Created by braindancer on May 17, 2009.
Edited by bekasu, jhodgdon, christefano. Log in to edit this 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');

Comments

It doesn't work

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

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;

node form javascript in frontend

The example is working, but when I printing the node form in frontend, there are no scripts (js) that exists in admin pages,for open/close fields (I have printed the $closure variable, but it did'n help).
So, somebody knows how to include scripts for node form in frontend?

node form javascript in frontend

The example is working, but when I printing the node form in frontend, there are no scripts (js) that exists in admin pages,for open/close fields (I have printed the $closure variable, but it did'n help).
So, somebody knows how to include scripts for node form in frontend?

'$node' used in the above

'$node' used in the above code conflicts if you are trying to display the node form in another node page.

Caused me a lot of grief.
:)

Not sure

Using $node did not make a difference for me. The problem was solved by including as described above. I tested using $node and my form displayed fine and I did see any errors resulting from that in watchdog.

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Programmers

Theming Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.