HTML button formmethod property
Examples
Submit a form with two buttons, the first submit button using method = "get" to submit the form data, the second submit button using method = "post" submission form data:
<form action="demo_form.html" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<button type="submit">提交</button>
<button type="submit" formmethod="post" formaction="demo_post.html">
使用 POST 提交</button>
</form>
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<button type="submit">提交</button>
<button type="submit" formmethod="post" formaction="demo_post.html">
使用 POST 提交</button>
</form>
try it"
Browser Support
Internet Explorer 10, Firefox, Opera, Chrome, and Safari support formmethod property.
Note: Internet Explorer 9 and earlier versions do not support IE formmethod property.
Definition and Usage
formmethod property developed HTTP method used to send the form data. formmethod property overrides form element's method attribute.
formmethod attributes required and type = "submit" used in conjunction.
Form-data can be sent in the following ways:
- In URL variable (using method = "get") to send the form
- In HTTP post (using method = "post") to send the form
Use "get" method:
- Form data in the URL to the name / value pair appears.
- Get the amount of data transferred is small, no larger than 2KB, mainly because by URL length limit.
- Do not use the "get" method for transmitting sensitive information! (Passwords or sensitive information will appear in the browser's address bar)
Using the "post" method:
- Send form data in HTTP post form.
- Stronger and more secure than "get" method.
- No size limit
Differences between HTML 4.01 and HTML5
formmethod property is new in HTML 5 attributes.
grammar
<button type="submit" formmethod="get|post">
Property Value
值 | 描述 |
---|---|
get | 向 URL 追加表单数据(form-data):URL?name=value&name=value |
post | 以 HTTP post 事务的形式发送表单数据(form-data) |
HTML <button> tag