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
Can you describe the bigger
Can you describe the bigger problem you're trying to solve? Are you just trying to programmatically create an 'enquiry' object? There are much easier ways to do that programmatically than what you're doing. I kind of doubt using drupal_execute in this way is the easiest solution to your problem.
The specific error message you're seeing is because there's no function called enquiry_node_edit, and you must pass a valid callback function with when calling drupal_get_form.
This worked for me in
This worked for me in tempalte.php
I am strugling with CALLBACKs now, only one half way useful tutorial on this here (http://www.computerminds.co.uk/drupal-6-multiple-instances-same-form-one...) but it does not work for me yet, getting errors because i cannot make drupal call hook_forms :(
Very thank's
if(!function_exists("node_object_prepare")) {
include_once(drupal_get_path('module', 'node') . '/node.pages.inc');
}
This is very important ! :)