4

I have a form with 3 different "Submit" buttons, and I want each of them to map to a particular Submit handler.

I have included these items using the following, generic, pattern:

                    array(
                        '#prefix' => '<td>',
                        '#suffix' => '</td>',
                        '#type' => 'submit',
                        '#value' => 'Update',
                        '#submit' => array('user_profile_details_edit_phone_submit')
                    )

But, every time I click the "Submit" button, the incorrect function is called. The function that IS called is the LAST function I add to a submit handler in this way.

Am I doing something wrong?

  • 1
    If the button labels are all the same that would make sense – Clive Dec 12 '13 at 16:30
  • By "label" do you mean whatever is in "#value"? Edit: Wow, that was it. Why the heck can't I have more than one button with the same name? – tigertrussell Dec 12 '13 at 16:34
  • 1
    Yes sorry, the submit value. It's because Drupal uses the value to decipher which button was clicked. I wonder does setting a specific #name for each button fix it? – Clive Dec 12 '13 at 16:43
  • That did it! Thanks, Clive. Want to move your response to an answer, and I'll accept/upvote it? Thanks for all of your help! – tigertrussell Dec 12 '13 at 16:53
  • No worries, I thought it sounded familiar :) – Clive Dec 12 '13 at 17:03
2

Drupal uses the name and value of submit buttons to identify which was pressed, and subsequently which submit handlers to run. If the names and values of all three buttons are the same, the FAPI will only be able to use one of them (in this case the last one).

To fix it you can assign a unique #name property to each of the buttons.

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.