Difference between form method get and post

When we define a form in HTML, we can set “method” property of form to be either “get” or “post”.

When the form property is set as “get”, the form data is set as name/value pairs and is shown in URL.

For example:

<html>
<body>
<form id="frm" name="frm" action="target.php" method="get">
  First name: <input id="fname" name="fname" type="text" value="Ali" ><br>
  Last name: <input id="lname" name="lname" type="text" value="Khan" ><br>
  <input id="btnsubmit" name="btnsubmit" type="submit" value="Submit">
</form>
</body>
</html>

When the above form is submit, the following should be shown on URL

http://target.php?fname=Ali&lname=Khan&btnsubmit=Submit

Alternatively, when the method=”post”, the name/value pairs will not be included in the URL

For example:

<html>
<body>
<form id="frm" name="frm" action="target.php" method="post">
  First name: <input id="fname" name="fname" type="text" value="Ali" ><br>
  Last name: <input id="lname" name="lname" type="text" value="Khan" ><br>
  <input id="btnsubmit" name="btnsubmit" type="submit" value="Submit">
</form>
</body>
</html>

When the above form is submit, it will show the following in URL (just target page name is shown)

http://target.php

Add a Comment

Your email address will not be published. Required fields are marked *

Spam Protection by WP-SpamFree