HTML input Tag formmethod Attribute Tutorial

In this section, we will learn what the formmethod is and how to use it.

What is formmethod Attribute in HTML <input> Tag?

First of all, the formmethod attribute is used with <input> elements of type image and submit.

We use this attribute when we want to set the HTTP method that should be used to set the form data to a server.

Two main values that we set for this attribute are POST and GET. These are explained in the rest of this section.

HTML formmethod Attribute in <input> Tag Syntax:

<input type = “image | submit” formmethod = “POST | GET”>

<input> Tag formmethod Attribute Values

The two main values for the formmethod are:

  • POST: use this value when you want to use HTTP POST method.
  • GET: use this value when you want to use HTTP GET method.

If we use HTTP GET method:

  • The form data will be appended into the URL as pairs of name-value. This means anyone can see what we’re sending to the target server. (Basically, the data is not encoded in this case).
  • The length of a URL is limited (about 3000 characters). This means we can’t use this method for sending large form data.
  • As mentioned before, this method is not secure! So it should not be used for sending sensitive data (like username and password) to servers.

If we use HTTP POST method:

  • The data will be inside the body of the HTTP request and this means people can’t see it in the URL anymore.
  • There’s no size limitation. So we can send large form data to a server.

Using POST method, however, will stop users from bookmarking the form data. But if you think about it, for security reasons, this is a good thing.

Example: using formmethod attribute in HTML <input> tag

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

Facebook
Twitter
Pinterest
LinkedIn

Top Technologies