How do I pre-populate a node edit form before I render it?

Events happening in the community are now at Drupal community events on www.drupal.org.
karimahmed's picture

I need to render a partially populated node edit form and have got it working to the point of programmatically creating and submitting the form using drupal_execute() but cannot then see how to render the partially populated form for the user to complete.

Any ideas please?


/**
* Implementation of a Drupal action.
* Create a new enquiry node and populate the passed contractors in the contractors CCK field.
* @param $objects array of contractor node IDs
* @param $context array of other parameters
*/
function contractor_enquiry(
$objects,
$context = array()
) {
global $user;

$form_state = array();
module_load_include('inc', 'node', 'node.pages');

$node = array('type' => 'enquiry');

$form_state['values'] = array(
'title' => '',
'body' => '',
'name' => $user->name,
'op' => t('Save')
);

drupal_execute('enquiry_node_form', $form_state, (object)$node);

/*
All is fine to here and the form has been validated (but not displayed) but then the following line produces an error:

warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'enquiry_node_edit' was given in C:\Documents and Settings\All Users\Documents\My Websites\safeguard-6\includes\form.inc on line 371.
*/
$output = drupal_get_form( 'enquiry_node_edit', (object)$node );

}

Comments

I suggest You should try

alexku's picture

I suggest You should try adding this line

<?php
module_load_include
('inc', 'node', 'node.pages');
?>

Brighton

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: