Is having multiple submit buttons on an HTML form a bad practice?

I am creating a multiple choice quiz for HTML and I know about a technique that would allow me to use several submit buttons - one for each answer to a separate question. Then I could process the form in PHP using the values โ€‹โ€‹of the submit button and determine which answer the user chose. The reason for using the submit buttons is that they can be styled accordingly.

However, I am wondering if this is bad practice in terms of accessibility? Would it be better to use an individual form for each answer to a question? There are many questions here about how to use multiple submit buttons, but they don't seem to touch this point.

+4
source share
2 answers

This is completely normal, and in many cases can improve the usability of the form. However, be careful as there are a couple of fixes:

  • If the enter key is used to submit the form, the submit behavior is undefined. HTML5 defines this behavior and indicates what most browsers already do in this situation: the first submit button on the form should have its name / value sent as part of the view.

    However, IE <= 8 does not send a name / value pair for any submit button when the input key is used to submit the form.

    So, you should know that there should be a โ€œdefault actionโ€ for the form, and this should be the first submission element.

  • You cannot use this technique to submit to another action based on a button click. Javascript could theoretically solve this, but you shouldn't do it (good mantra, don't use Javascript to solve a problem other than Javascript).

+3
source

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

+2
source

Source: https://habr.com/ru/post/1338682/


All Articles