Skip to content
Related Articles

Related Articles

Improve Article
How to define the HTTP method for sending data to the action URL in HTML5?
  • Difficulty Level : Expert
  • Last Updated : 12 Mar, 2021

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:




My Personal Notes arrow_drop_up
Recommended Articles
Page :