Consider the following form in a 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 produces a request payload of confirm=1
. Similarly the second button results in re-send=1
and the third cancel=1
.
Examining the request payload server-side allows me to determine which of the three buttons were clicked (assuming only one of the three keys are present in the request payload).
In all cases, the key:value pairs of the non-clicked buttons are excluded from the request payload. This is very useful.
Is this behaviour (that non-clicked button key:value pairs are excluded from the request payload) standard?
When a user submits a form (the submit button clicked), the default action of the form is to submit the form's data to a URL that processes the data. Form elements have the action and method attributes which specify the URL to submit the form to and the type of request ( get , post , and so on), respectively.
yes, multiple submit buttons can include in the html form.
Create another button with type submit. Also add a 'formaction' attribute to this button and give it the value of the secondary URL where you want to send the form-data when this button is clicked. The formaction attribute will override the action attribute of the form and send the data to your desired location.
Sometimes the problem is caused by old versions of the Javascript files, cached by your browser and can be fixed by clearing the browser cache. You can use the browser console of your browser for debugging. After the Javascript error is fixed, the submit button will automatically be enabled.
As far as 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 its control name paired with its current value as part of the submitted form data set. ... If a form contains more than one submit button, only the activated submit button is successful.
From HTML5 spec: http://www.w3.org/TR/2012/CR-html5-20121217/forms.html#the-button-element
Note: A button (and its value) is only included in the form submission if the button itself was used to initiate the form submission.
I'm pretty sure < IE8 will submit the element contents instead of value (e.g. confirm=Confirm) but most 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 that some older browsers may have scenerios where they might treat it as though no button was clicked (e.g. form submitted by javascript or enter button instead). Might be worth catering for this by defaulting to "confirm". HTML5 on modern browsers shouldn't give you any grief, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With