html5 - HTML form, multiple submit buttons, post payload ignores non-clicked buttons: Is this standard behaviour? -


consider following form in 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 first button produces request payload of confirm=1. second button results in re-send=1 , third cancel=1.

examining request payload server-side allows me determine of 3 buttons clicked (assuming 1 of 3 keys present in request payload).

in cases, key:value pairs of non-clicked buttons excluded request payload. useful.

is behaviour (that non-clicked button key:value pairs excluded request payload) standard?

as far i'm aware, yes.

from html4 spec: http://www.w3.org/tr/1999/rec-html401-19991224/interact/forms.html#h-17.13.2

every successful control has control name paired current value part of submitted form data set. ... if form contains more 1 submit button, activated submit button successful.

from html5 spec: http://www.w3.org/tr/2012/cr-html5-20121217/forms.html#the-button-element

note: button (and value) included in form submission if button used initiate form submission.

i'm pretty sure < ie8 submit element contents instead of value (e.g. confirm=confirm) other common browsers should work correctly.

perhaps consider:

<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> 

also, it's worth noting older browsers may have scenerios might treat though no button clicked (e.g. form submitted javascript or enter button instead). might worth catering defaulting "confirm". html5 on modern browsers shouldn't give grief, though.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -