I have two submit buttons in a form. How do I determine which one was hit serverside?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
use formaction HTML attribute
You can give each input a different value and keep the same name:
Then in the code check to see which was triggered:
The only problem with that is you tie your logic to the text within the input. You could also give each one a unique name and just check the $_POST for the existence of that input:
And in the code:
An even better solution consists of using button tags to submit the form:
This way there is no inconvenience with internationalization and multiple display languages (in the former solution, the label of the button is also the value sent to the server).
If you give each one a name, the clicked one will be sent through as any other input.
You can also do it like this (I think it's very convenient if you have N inputs).
And then in the server side (PHP in my example) you can read "row" as an array to get the index:
$_POST['row'] will be an array with just one element, in the form index => value (for example: '2' => 'something").
http://php.net/manual/en/function.key.php
Maybe the suggested solutions here worked in 2009, but ive tested all of this upvoted answers and nobody is working in any browsers.
only solution i found working is this: (but its a bit ugly to use i think)