2

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?

2 Answers 2

2

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']);
2

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

3
  • This is valid also for $form['#submit'] for which the code is similar to array_unshift($form['#submit'], 'mymodule_form_submit').
    – apaderno
    Commented Aug 17, 2011 at 12:54
  • @kiamlaluno Me thinks this would affect all buttons on the form.
    – Oswald
    Commented Aug 17, 2011 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
    Commented Aug 17, 2011 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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