There are two (multiple) submit in a form in HTML. how to distinguish between the backend (pure HTML implementation without javascript) and formjavascript
A form may have multiple Submit elements. How can I identify which button is clicked in the background?
Many people on the Internet say that javascript is used to write a long function and click different buttons to submit different data. In other words, multiple forms are used. In fact, this is not necessary.
The two methods can be implemented without using javascript.
Method 1: use different name attributes
<form method="post">
<Input type = "submit" name = "save" value = "save settings"/>
<Input type = "submit" name = "reset" value = "reset Settings"/>
</form>
Background PHP processing:
if ( $_REQUEST['save'] ) {
// ...
} elseif ( $_REQUEST['reset'] ) {
// ...
}
The reason is that only the data of the clicked submit button will be submitted.
Method 2: Use the same name and different values
<form method="post">
<Input type = "submit" name = "action" value = "Save settings"/>
<Input type = "submit" name = "action" value = "Reset Settings"/>
</form>
Background PHP processing:
If ($ _ REQUEST ['action'] = 'Save settings '){
// ...
} Elseif ($ _ REQUEST ['action'] = 'reset settings '){
// ...
}
Note that in method 2, the front and back-end encoding must be consistent because the Chinese characters are used. Otherwise, the judgment may fail.
Because<input type="submit"/>
Element,value
The attribute is the text to be displayed on the button. It is very likely to use Chinese characters and may need to be modified because of the front-end. The background Code also needs to be modified, so the second method is not recommended, method 1 is recommended.
This article by jzj1993 original, reproduced please note Source: http://www.hainter.com/html-form-submit