English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
This article introduces the usage of the HTML button formmethod attribute, with online examples demonstrating how to use the HTML button formmethod attribute, browser compatibility, syntax definition, and detailed information about its attribute values.
A form with two submit buttons. The first submit button submits form data using method ="get", and the second submit button submits form data using method ="post":
!DOCTYPE html <html> <head> <title>HTML:<button> formmethod attribute - Basic Tutorial Website oldtoolbag.com</title> <body> <form action="action_page.php" method="get"> First name: <input type="text" name="fname"><br> Last name: <input type="text" name="lname"><br> <button type="submit">Submit in default get method</button> <button type="submit" formmethod="post">Submit in post method</button> </form> </body> </html>Test and see ‹/›
IEFirefoxOperaChromeSafari
Internet Explorer 10, Firefox, Opera, Chrome, and Safari support the formmethod attribute.
Note:Internet Explorer 9 and earlier IE versions do not support the formmethod attribute.
The formmethod attribute specifies the HTTP method to be used when submitting form data. This attribute overrides the form's method attribute.
The formmethod attribute is only used for buttons of type "submit".
Form data can be sent as URL variables (using method = "get") or as HTTP post (using method = "post").
注意事项 about the "GET" method:
It will submit form data by name/Attach the value in the form of key-value pairs to the URL
Very useful for form submissions where the user wants to add the result as a bookmark
How much data you can place in the URL is limited (there may be differences between browsers), so you cannot be sure that all form data will be transmitted correctly
Never use the "get" method to pass sensitive information! (Passwords or other sensitive information will be displayed in the browser's address bar)
Note on the "post" method:
It sends form data as an HTTP post transaction
Form submissions with the "post" method cannot be added as bookmarks
It is more robust and secure than "get"
It has no size limit
The formmethod attribute is an HTML 5 of the new attribute.
<button type="submit" formmethod="get|post">
Value | Description |
---|---|
get | Append form data to URL (form-data):URL?name=value&name=value |
post | Send form data in the form of an HTTP POST transaction (form-data) |