Open In App

How to define the HTTP method for sending data to the action URL in HTML5?

Last Updated : 12 Mar, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will learn how to define an HTTP method to send data to the action URL. The method attribute is used to indicate how form data can be sent to the given server in the action URL. The form-data may be sent using the GET or POST method depending on the requirement.

The differences between the GET and POST method are defined below:

1. GET Method

  • The form-data is sent in name/value pairs in the URL.
  • The URL is limited in length to about 3000 characters.
  • Sensitive information like passwords should not be sent using the GET method as it would be visible in the URL of the request.

2. POST Method

  • The form-data is appended within the HTTP request body.
  • There are no restrictions on the size of the data due to this.
  • Sensitive data could be sent using this method as it is not visible in the URL of the request.

Syntax:

<form method="get|post">

The below examples demonstrate the sending of data using the available methods:

Example 1: Using the GET method.

HTML




<html>
<body>
<h1 style="color: green;">
  GeeksforGeeks
</h1>
<form action="form.php" method="get"
      target="_blank">
  <label for="name">Name:</label>
  <input type="text" id="name" name="name">
  <br><br>
  <label for="age">Age:</label>
  <input type="number" id="age" name="age">
  <br><br>
  <input type="submit" value="Submit">
</form>
</body>
</html>


Output:

Example 2: Using the POST method.

HTML




<html>
<body>
<h1 style="color: green;">
  GeeksforGeeks
</h1>
<form action="form.php" method="post"
      target="_blank">
  <label for="name">Name:</label>
  <input type="text" id="name" name="name">
  <br><br>
  <label for="age">Age:</label>
  <input type="number" id="age" name="age">
  <br><br>
  <input type="submit" value="Submit">
</form>
</body>
</html>


Output:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads