HTML <button> formmethodAttributes

HTML button 标签参考手册HTML <button> Tag

Examples

A form with two submit buttons. The first submit button submits the form data using method="get", and the second submit button submits the form data using method="post":

<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">Submit</button>
<button type="submit" formmethod="post" formaction="demo_post.html">
Submit using POST</button>
</form>

Try it »

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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.


Definition and Usage

The formmethod attribute specifies the HTTP method used to send form data. The formmethod attribute overrides the form element'smethodattribute.

The formmethod attribute must be used with type="submit".

Form-data can be sent in the following ways:

  • Sent as URL variables (using method="get")
  • Sent as an HTTP post (using method="post")

Using the "get" method:

  • Form data appears in the URL as name/value pairs.
  • The amount of data sent by get is small, cannot be greater than 2KB, mainly because it is limited by URL length.
  • Do not use the "get" method to send sensitive information! (Passwords or sensitive information will appear in the browser's address bar)

Using the "post" method:

  • Send form data as an HTTP post.
  • More powerful and more secure than the "get" method.
  • No size limit

Differences between HTML 4.01 and HTML5

The formmethod attribute is a new attribute in HTML5.


Syntax

<button type="submit" formmethod="get|post">

Attribute Values

Value Description
get Appends form-data to the URL: URL?name=value&name=value
post Sends form-data as an HTTP post transaction.


HTML button 标签参考手册HTML <button> Tag Other extensions