HTML form Tag method Attribute Tutorial

In this section, we will learn what method attribute is and how to use it.

What is method Attribute in HTML <form> Tag?

Sending a form data to a server is done via HTTP methods.

The two main methods for sending a form data to a server are POST and GET.

This means for the value of the method attribute, we could either set the value “POST” if we want to use the HTTP “POST” method, or “GET” if we want to send the data via HTTP “GET” method.

If we use HTTP GET method:

  • The form data will be appended to the URL as pairs of name-values. 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.

HTML method Attribute in <form> Tag Syntax:

<form method = “POST | GET”> </form>

<form> Tag method Attribute Values

As mentioned before, there are two values that could be used for the method attribute:

  • POST: if we want to use the HTTP POST method to send the form data to a server.
  • GET: if we want to use the HTTP GET method to send the form data to a server.

Example: using method attribute in HTML <form> tag

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

Facebook
Twitter
Pinterest
LinkedIn

Top Technologies