English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

Comprehensive HTML Tags

HTML: <button> formmethod attribute

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.

 HTML <button> tag

Online Example

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 ‹/›

Browser Compatibility

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.

Definition and Usage

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:

  1. It will submit form data by name/Attach the value in the form of key-value pairs to the URL

  2. Very useful for form submissions where the user wants to add the result as a bookmark

  3. 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

  4. 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:

  1. It sends form data as an HTTP post transaction

  2. Form submissions with the "post" method cannot be added as bookmarks

  3. It is more robust and secure than "get"

  4. It has no size limit 

HTML 4.01 between HTML5difference

The formmethod attribute is an HTML 5 of the new attribute.

Syntax

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

Attribute value

ValueDescription
getAppend form data to URL (form-data):URL?name=value&name=value
postSend form data in the form of an HTTP POST transaction (form-data)
 HTML <button> tag