HTML <input> formmethodAttribute
Examples
The second submit button overrides the form's HTTP method:
<form action="demo-form.php" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="提交">
<input type="submit" formmethod="post" formaction="demo-post.php" value="Submit using POST">
</form>
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="提交">
<input type="submit" formmethod="post" formaction="demo-post.php" value="Submit using POST">
</form>
Try it Yourself »
Browser Support
![]()
![]()
![]()
![]()
![]()
Internet Explorer 10, Firefox, Opera, Chrome, and Safari support the formmethod attribute.
Note:Internet Explorer 9 and earlier versions do not support the formmethod attribute of the <input> tag.
Definition and Usage
The formmethod attribute defines the HTTP method for sending form-data to the action URL.
The formmethod attribute overrides the <form> element'smethodattribute.
Note:The formmethod attribute is used with type="submit" and type="image".
Form data can be sent as URL variables (method="get") or as HTTP post transactions (method="post").
Notes on the "get" method:
- This method appends form data to the URL in name/value pairs.
- This method is useful for form submissions that users want to bookmark.
- The URL is limited in length (browsers have different limits), therefore, you cannot be sure that all form data will be correctly transmitted.
- Never use the "get" method to send sensitive data! (For example, passwords or other sensitive information is visible in the browser's address bar).
Notes on the "post" method:
- This method sends form data as HTTP post transactions.
- Forms submitted with the "post" method cannot be bookmarked.
- The "post" method is more secure than "get", and "post" has no length limitations.
Differences Between HTML 4.01 and HTML5
The formmethod attribute is new in HTML5.
Syntax
<input formmethod="get|post">
Attribute Values
| Value | Description |
|---|---|
| get | Default. Appends form-data to the URL in name/value pairs: URL?name=value&name=value. |
| post | Sends form-data as an HTTP post transaction. |
HTML <input> Tag Other Extensions