[development] RE : Form with multiple submit buttons

fgm fgm at osinet.fr
Wed Oct 7 06:56:02 UTC 2009

Note that if the label on the buttons (#value property) is the same, FAPI will always return the last button: you need to have different #value on submits for op to be returned differently.
De : development-bounces at drupal.org [development-bounces at drupal.org] de la part de Ken Winters [kwinters at coalmarch.com]
Date d'envoi : mardi 6 octobre 2009 22:15
À : development at drupal.org
Objet : Re: [development] Form with multiple submit buttons

If you look at the HTML source, the submit button's name is "op" - in the comment form, this lets you switch whether to preview or post, for example.  The comment module is probably a good place to look at code, too.

- Ken Winters

On Oct 6, 2009, at 3:57 PM, nitin gupta wrote:


I am having two form submit buttons on a single page, somethings like this:

$form['submit1'] = array(
    '#type' => 'submit',
    '#value' => t('save'),
    '#submit' => array('test_submit1'),


[some more for elements in between]

  $form['submit2'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#submit' => array('test_submit2'),


Now, whether I click on any of them, the submit callback of second button is called always. But if I change the value of second button or give them different '#name', everything gets back in place. They call their submit functions respectively.

I did not expect such a behavior given this:


Although, they both have same #value but will have different ids in the form, so Drupal has every reason to differentiate between them (or not??). Why is such thing happening? Am I missing something?

Nitin Kumar Gupta

More information about the development mailing list