Horje
How to create The Method Attribute in HTML Form

The method attribute specifies the HTTP method to be used when submitting the form data.

The form-data can be sent as URL variables (with method="get") or as HTTP post transaction (with method="post").

The default HTTP method when submitting form data is GET. 


Example of The get Method Attribute in HTML Form

This example uses the GET method when submitting the form data:
index.html
Example: HTML
<form action="/action_page.php" target="_blank" method="get">

Full Example of The get Method Attribute in HTML Form

This example uses the GET method when submitting the form data:

index.html
Example: HTML
<!DOCTYPE html>
<html>
<body>

<h2>The method Attribute</h2>

<p>This form will be submitted using the GET method:</p>

<form action="/action_page.php" target="_blank" method="get">
  <label for="fname">First name:</label><br>
  <input type="text" id="fname" name="fname" value="John"><br>
  <label for="lname">Last name:</label><br>
  <input type="text" id="lname" name="lname" value="Doe"><br><br>
  <input type="submit" value="Submit">
</form>

<p>After you submit, notice that the form values is visible in the address bar of the new browser tab.</p>

</body>
</html>

Output should be:

Full Example of The get Method Attribute in HTML Form

Example of The post Method Attribute in HTML Form

This example uses the POST method when submitting the form data:

index.html
Example: HTML
<form action="/action_page.php" method="post">

Full Example of The post Method Attribute in HTML Form

This example uses the POST method when submitting the form data:

index.html
Example: HTML
<!DOCTYPE html>
<html>
<body>

<h2>The method Attribute</h2>

<p>This form will be submitted using the POST method:</p>

<form action="/action_page.php" target="_blank" method="post">
  <label for="fname">First name:</label><br>
  <input type="text" id="fname" name="fname" value="John"><br>
  <label for="lname">Last name:</label><br>
  <input type="text" id="lname" name="lname" value="Doe"><br><br>
  <input type="submit" value="Submit">
</form>

<p>After you submit, notice that, unlike the GET method, the form values is NOT visible in the address bar of the new browser tab.</p>

</body>
</html>

Output should be:

Full Example of The post Method Attribute in HTML Form

Notes on GET:

Notes on POST:

Tip: Always use POST if the form data contains sensitive or personal information!






Category:
Web Tutorial
Sub Category:
HTML Form Attributes
Uploaded by:
Admin


Read Article
https://develop.horje.com/learn/1434/reference