I want to build a custom edit form for a existing node. The edit form should not show all fields and should be populated with the existing field values. Furthermore I want to add a few custom submit buttons. I know I can pre populate the fields with #default_value, but there are quite a lot of fields I have to pre populate like that, so I wanted to pre populate them all at once.
I have made a form function with the following code:
$node = (array)node_load($nid);
$form_state = array();
$form_state['values'] = $node;
$form = node_form($form_state, $node);
drupal_prepare_form('node_form', $form, $form_state);
I have also defined a custom submit button:
$form['submit_one'] = array(
'#type' => 'submit',
'#value' => t('Gereed'),
'#weight' => 10,
'#submit' => array('custom_form_submit_one'),
);
And a submit handler:
function custom_form_submit_one($form_id, $form_values) {
watchdog ("Hello","Hello");
}
When I press the submit button, the submit handler is not called.
When I disable the statement:
$node = (array)node_load($nid);
and I press the submit button, the submit handler is called. However, my form is not pre populated with the values.
Is it possible what I want to do? Can I use a custom form and pre populate the fields (without specifying #default_value for each field)?