Open In App

What is formmethod Attribute in HTML Form ?

Last Updated : 16 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

What is formmethod Attribute?

The formmethod attribute in HTML is used to define a HTTP technique that specifies how to send form-data to the backend server.  This attribute is apply on <button> , <input type= “submit”> and <input type=”image”>. It overrides the feature of the method attribute of the <form> element. 

How to send data?

The data can be sent to the server by using the URL variables using the GET method and as an HTTP post by using the POST method. 

What is the GET and POST Method?

  • GET Method: In the GET method, after the submission of the form, the form values will be visible in the address bar of the new browser tab. It has a limited size of about 3000 characters. It is only useful for non-secure data but not for sensitive information. It supports Bookmarking the result. It can’t be used to send binary data.
  • POST Method: In the post method, after the submission of the form, the form values will not be visible in the address bar of the new browser tab as it was visible in the GET method. It appends form data inside the body of the HTTP request. It has no size limitation. This method does not support bookmarking of the result.

Example: In this example, we will use formmethod attribute.

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>
        What is formmethod Attribute in HTML?
    </title>
    <style>
        h3 h2 {
            font-family: impact;
        }
    </style>
</head>
 
<body style="text-align: center;">
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>
    <h3>What is formmethod Attribute in HTML?</h3>
    <form action="#" id="users" action="#"
          method="GET" target="_blank">
        User_id:
        <input type="email" name="email"
               placeholder="Emter Email Id" />
        <br /><br />
        Password:
        <input type="password" name="pword"
               placeholder="Enter Password" />
        <br /><br />
        <input type="submit" value="Submit using GET method"
               formmethod="get" />
        <input type="submit" formaction="#"
               value="submit using POST method"
               formmethod="post" />
    </form>
</body>
 
</html>


Output:

Submit form using POST Method:

Submit form using GET Method:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads