HTML form, multiple submit buttons, mail payload ignores buttons without clicking: Is this standard behavior?

Consider the following view in an HTML5 document:

<form method="post" action="http://example.com/submit/"> <button name="confirm" value="1" type="submit">Confirm</button> <button name="re-send" value="1" type="submit">Re-send code</button> <button name="cancel" value="1" type="submit">Cancel change</button> </form> 

Using Chrome, clicking the first button creates the payload of the confirm=1 request. Similarly, the second button results in re-send=1 and three cancel=1 .

Examining the server side of the request payload allows me to determine which of the three buttons was pressed (provided that only one of the three keys is present in the request payload).

In all cases, the key: key pairs are not excluded from the request payload. It is very useful.

Is this behavior (that the key button is not pressed: value pairs are excluded from the request payload)?

+6
source share
1 answer

As far as I know, yes.

From the HTML4 specification: http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.13.2

Each successful control has its own control name paired with its current value as part of the submitted form data set .... If the form contains more than one submit button, only the activated submit button is successful.

From the HTML5 specification: http://www.w3.org/TR/2012/CR-html5-20121217/forms.html#the-button-element

Note. The button (and its value) is included only in the form submission, if the button itself was used to initiate the submission of the form.

I am sure that <IE8 will present the contents of the element instead of the value (e.g. confirm = Confirm), but most other normal browsers should work correctly.

Perhaps think:

 <form method="post" action="http://example.com/submit/"> <button name="submit-action" value="confirm" type="submit">Confirm</button> <button name="submit-action" value="re-send code" type="submit">Re-send code</button> <button name="submit-action" value="cancel change" type="submit">Cancel change</button> </form> 

In addition, it is worth noting that some older browsers may have scenerios, where they can handle it as if no button had been pressed (for example, the form provided by javascript or the enter key). Maybe it's worth it to "confirm." However, HTML5 in modern browsers should not upset you.

+1
source

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


All Articles