I want to execute my custom submission handler for a button before any other submission handler associated with that button. How could I do this?


array_unshift() the name of the function onto the "#submit" array of the button.

  • This is valid also for $form['#submit'] for which the code is similar to array_unshift($form['#submit'], 'mymodule_form_submit').
    – apaderno
    Aug 17 '11 at 12:54
  • @kiamlaluno Me thinks this would affect all buttons on the form.
    – Oswald
    Aug 17 '11 at 19:01
  • I know; I was pointing out to who reads that the same code can be used with $form['#submit'], not that in this case the code should alter both the buttons' submission handler and the form submission handler.
    – apaderno
    Aug 17 '11 at 19:59

You should add it at the first position in handlers array.

$form['actions']['submit']['#submit'] = array_merge( array('your_form_submit'), $form['actions']['submit']['#submit']);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.