Pedro Posada | How to embed a node form into a page in Druapl 6

How to embed a node form into a page in Druapl 6

Posted on February 19, 2009 - 12:37pm
<< 23 of 50 >>

I was trying to do the same on drupal 6.x I used to do with drupal 5.x to post a form inside a node. In oder words, to embed a node add form inside the body text area of a page. But I was getting fatal errors. I went to drupal.org site and found out that 6.x doesn't include some files when rendering the pages.

http://drupal.org/node/312189

Basically this is what I used to do on Drupal 5.x:

  <?php

print node_add('my_content_type');

?>
But on Drupal 6.x you need to put:
<?php

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

?>

Another alternative:

<?php
global $user;

if( !
function_exists("node_object_prepare")) {
   include_once(
drupal_get_path('module', 'node') . '/node.pages.inc');
}
$type = 'your content type';

// Initialize settings:
$node = array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, 'language' => '');

print
drupal_get_form($type .'_node_form', $node);
?>

By using this code, you can set a custom title for the page dynamically.

 

Interesting node form embed module

Post new comment

The content of this field is kept private and will not be shown publicly.
Please solve the math question. This way we will know you are not a robot.