I'm adding an additional button to the user_profile_form that lets them jump to different page in addition to just saving their settings (which just loads the same form with settings applied)
function mymodule_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_profile_form') {
$form['save_and_add_pets'] = array(
'#type' => 'submit',
'#value' => 'Save & Do Other Stuff',
'#submit' => array('my_custom_func'),
);
}
}
function my_custom_func($form, $form_state) {
user_profile_form_submit($form, $form_state);
drupal_goto('this/other/page');
}
The functon is never called. However, if I use $form['#submit'][] = 'my_custom_func'; in this mymodule_form_alter(), it works, but I have no way to differentiate which button triggered it ('Save' or my custom button).
Is it possible to use a per-submit button '#submit' handler in hook_form_alter()?
Is there any way to add a custom button/callback to a core form like this?
thanks
Comments
Comment #1
Liembo-1 commentedI figured it out. I was using hook_button to render the input as a button html type instead, so its (as designed) posting without triggering submit hooks. I did this because I was attempting to use http://www.filamentgroup.com/lab/styling_the_button_element_with_sliding... to style the input buttons.
Looks like I will need to find a different way to style my submit buttons that allows me to retain the use of 'input' rather than convert them to 'button' types. Or figure out how to have a [button type='submit'...] tag able to trigger submit handlers like a real [input type='submit'..] tag.
Comment #2
pfrenssenSet status according to #1.