Handle multiple submit buttons in Drupal form API
Asked 07 September, 2021
Viewed 1.1K times
  • 56
Votes

I have 2 submit buttons and want to perform different actions for each submit button . Here I want to set the form fields which can be done only in form_alter(). Can anyone suggest how to check for multiple submit buttons in the form_alter() function?

I have used

function myform_form_submit($formID, &$form_state) {
if($form_state['clicked_button']['#value'] == $form_state['values']['submit_one'])    //if button 1      is clicked
     $form_state['redirect'] = 'mypath/page_one';   //redirect to whatever page you want
 else if($form_state['clicked_button']['#value'] == $form_state['values']['submit_two'])  /if button      2 is clicked
    $form_state['redirect'] = 'mypath/page_two';
 }

but this does not work

3 Answer