Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is putting multiple submit buttons on an HTML form bad practice?

I'm building an HTML multiple-choice quiz and am aware of a technique which would let me use multiple submit buttons - one for each answer to an individual question. I could then process the form in PHP using submit button values and determine which answer the user has selected. The reason for using submit buttons is so that they can be styled appropriately.

However, I'm wondering if this is bad practice from an accessibility perspective? Would it be better to use an individual form for each answer to a question? There are plenty of questions on here about how to use multiple submit buttons but they don't seem to address this point.

like image 988
codecowboy Avatar asked Feb 07 '11 06:02

codecowboy


2 Answers

It's absolutely fine, and in a lot of cases can improve the usability of a form. Be careful however, as there are a couple of gotchas:

  1. If the enter key is used to submit the form, the submit behaviour is undefined. HTML5 does define this behaviour, and it specifies what most browsers already do in this situation: The first submit button in the form should have its name/value sent as part of the submission.

    However IE<=8 don't send the name/value pair for any submit button when the enter key is used to submit the form.

    So, you have to be aware that there needs to be a "default" action for the form, and that has to be the first submit element present.

  2. You can't use this technique to submit to a different action based on which button was pressed. Javascript can theoretically solve this, but you shouldn't do that (a good mantra is, don't use Javascript to solve a non-Javascript problem)

like image 95
Gareth Avatar answered Oct 07 '22 02:10

Gareth


What will you do if the form is submitted using the Enter key on the keyboard, and none of the submit buttons is in the data you receive server-side?

like image 20
Dan Grossman Avatar answered Oct 07 '22 02:10

Dan Grossman