Suppose I have the following HTML form:
<form> ... <input type="submit" name="queue" value="Queue item"> <input type="submit" name="submit" value="Submit item"> </form>
How do I know which button the user clicked (without using javascript)?
I looked at submitted data and it seems that when "Queue Item"
is clicked then "queue" = "Queue Item"
gets sent to the server. And when "Submit item"
is clicked then "submit" = "Submit item"
sets sent.
Can I rely on this behavior? Is it documented somewhere in the standard on HTML forms? How do you guys do it?
yes, multiple submit buttons can include in the html form. One simple example is given below.
The form will be submitted to the server and the browser will redirect away to the current address of the browser and append as query string parameters the values of the input fields.
No, a form has only one action.
Yes, you can rely on this; it's fully documented here. The specific relevant lines say:
When a form is submitted for processing, some controls have their name paired with their current value and these pairs are submitted with the form. Those controls for which name/value pairs are submitted are called successful controls.
and
If a form contains more than one submit button, only the activated submit button is successful.
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