I have two form submission buttons: the normal one and one added via hook_form_alter
.
I'm currently using the normal default one as a save button which updates the node content as normal.
The second one which is called submit does the same thing, but will be changing a checkbox via $form_state
prior to saving the node content.
The code I'm using is the following one:
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'example_node_form') {
//dpm($form);
$form['actions']['finishbutton'] = [
'#type' => 'submit',
'#value' => t('Submit'),
'#submit' => array_merge($form['actions']['submit']['#submit'], ['custom_submit']),
'#weight' => 99,
];
}
}
function custom_submit($form, &$form_state) {
drupal_set_message(t('This works, but shows up after the node submit message'));
// Shows after the node save message.
dpm($form_state);
// Doesn't update.
$form_state['values']['field_nomination_submitted'][LANGUAGE_NONE][0]['value'] = 1;
}
My submission works, but the custom handler appears to be firing after the standard submission handler. Do I need to switch the array_merge order? Do I need to break this into separate functions? Do I potentially need to add a submit function inside of custom_submit?
array_merge()
,custom_submit()
is put after the other submission handlers.