HTML button Tag formmethod Attribute Tutorial

In this section, we will learn what formmethod attribute is and how it works.

What is formmethod Attribute in HTML <button> Tag?

A form uses HTTP methods to send its data to a server. These methods typically are either “POST” or “GET”.

By default, we use the method attribute that belongs to HTML <form> element to set the HTTP method we want to be used for the target form element.

But HTML <button> element has also an attribute named formmethod that allows us to set the HTTP method that we want it to be used in order to send the form data to a server.

Note: if the target <form> element already has the method attribute set, using formmethod attribute overrides the value of the method attribute.

HTML formmethod Attribute in <button> Tag Syntax:

<button type = "submit" formmethod = "POST | GET"> </button>

<button> Tag formmethod Attribute Values

The value of the formmethod attribute is one of HTTP methods:

  • If we want to send the form data via HTTP get method, then the value of formmethod would be “GET”.
  • If we want to send the form data via HTTP post method, then the value of formmethod would be “POST”.

Example: using formmethod attribute in HTML <button> tag

See the Pen using formmethod attribute in HTML <button> tag by Omid Dehghan (@odchan1) on CodePen.

You might notice here that the form has the value “GET” set for its method attribute. But because the submit button has the value “POST” set for formenctype attribute, the final HTTP method will be used is POST for this form data.

Leave a Reply