Drupal 6: Load a CCK node $form object using drupal_retrieve_form

drupal_execute() is great for processing a form and drupal_get_form() is great for generating the html for a form, but what if you’d like to load the $form object to modify or embed it?

<?php

// include drupal's node include file
require("modules/node/node.pages.inc");

// create an empty $form_state array
$form_state = array();

// define the content type of the form you'd like to load
$nodeType = 'MYCCKNODETYPE';

// create a string of the $form_id
$form_id = $nodeType . '_node_form';

// create a basic $node array
$node = array('type' => $nodeType, 'uid' => $GLOBALS['user']->uid, 'name' => $GLOBALS['user']->uid);

// load the $form
$form = drupal_retrieve_form($form_id, $form_state, $node);

// prepare the $form
drupal_prepare_form($form_id, $form, $form_state);

// show the form structure, debug
echo "<PRE>";
print_r($form);
echo "</PRE>";

?>

Updated: