HTML <button> formmethod Attribute

Definition and Usage

formmethod attribute specifies the HTTP method used to send form data. This attribute overrides the form's method attribute.

formmethod attribute is only used for type="submit" button.

Form data can be sent as URL variables (using method="get"), or sent as an HTTP post (using method="post")

Points to consider for the "get" method:

  • It attaches the form data to the URL in the form of name/value pairs
  • This is very useful for form submissions where the user wants to bookmark the results
  • The amount of data that can be placed in the URL is limited (varies by browser), so it cannot be guaranteed that all form data can 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)

Points to consider for the "post" method:

  • It sends the form data as an HTTP POST transaction
  • Forms submitted using the "post" method cannot be saved as bookmarks
  • Compared to the "get" method, the "post" method is more robust and secure
  • It has no size limit

Example

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="/action_page.php" method="get">
  <label for="fname">First Name:</label>
  <input type="text" id="fname" name="fname"><br><br>
  <label for="lname">Last Name:</label>
  <input type="text" id="lname" name="lname"><br><br>
  <button type="submit">Submit</button>
  <button type="submit" formmethod="post">Submit with POST</button>
</form>

Try It Yourself

Syntax

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

Attribute Value

Value Description
get Attach form data to URL:URL?name=value&name=value.
post Send form data as an HTTP POST transaction.

Browser Support

The numbers in the table indicate the first browser version that fully supports this property.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
9.0 10.0 4.0 5.1 15.0

Note:formmethod Attributes are new properties in HTML 5.