HTML slt;button and formmethod properties

HTML button formmethod property HTML slt;button-and-label

The formmethod property defines how form-data is sent, which overrides the method property in the label, see the following example:

Forms with two submit buttons, the first submission button submits form data using method"get" and the second submit button submits 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">提交</button>
<button type="submit" formmethod="post" formaction="demo_post.html">
Use post to submit </ button>
</form>

Try it out . . .

Browser support

HTML button formmethod property HTML button formmethod property HTML button formmethod property HTML button formmethod property HTML button formmethod property

Internet Explorer 10, Firefox, Opera, Chrome, and Safari support formmethod properties.

Note: Formmethod properties are not supported in Internet Explorer 9 and earlier versions of IE.


Definitions and usages

The formmethod property establishes the HTTP method used to send form data. The formmethod property overrides the method property of the form element.

The formmethod property needs to be used in conjunction with type"submit".

Form-data can be sent in the following ways:

  • Sent as a URL variable (using method-"get").
  • Sends in the form of HTTP post (using method-"post").

Using the "get" method:

  • Form data appears in the URL as a name/value pair.
  • Get transmits a small amount of data that cannot be greater than 2KB, mainly due to URL length limitations.
  • Do not use the "get" method to transmit sensitive information! (Passwords or sensitive information appear in the browser's address bar)

Using the "post" method:

  • Send form data as HTTP post.
  • Stronger and safer than the "get" method.
  • There is no size limit

The difference between HTML 4.01 and HTML5

The formmethod property is a new property in HTML 5.


Grammar

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

The property value

value describe
get Add form data to the URL: URL? Name = Value & Name = Value
post Send form data in the form of HTTP POST transactions (FORM-DATA)


HTML button formmethod property HTML slt;button-and-label