Click here to Skip to main content
15,886,639 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<form name="frn" action="download.php?f=sample">
 <input type="submit" name="am" value="submit"/>
</form>


Why the above form is submitted to following?
download.php


If method='GET' is mentioned, why the form submits to following?
download.php?am=submit


if method='POST' is used, then only it submits to the original action string
download.php?f=sample


Why?
Posted

You need to know the basics about GET and POST method.

Please study the basics here:

http://www.plus2net.com/asp-tutorial/form-diff.php[^]

http://www.cs.tut.fi/~jkorpela/forms/methods.html[^]
 
Share this answer
 
The reason for this is the meaning for GET and POST of the attribute method of the form tag:

GET :
All data of the submitted form will be encoded as URL parameters
POST :
All data of the submitted form will be sent in the request header

That implies when you set the method to GET the field am with a value of "submit" will be sent in the parameters attached to the URL. If the method is set to POST the field names and values will be sent in the request header and thus the url will not have to be modified.
There actually is no reason to try what you did though. If you want some additional parameter to be submitted with the other form data you can just include a hidden field:
XML
<input type="hidden" name="f" value"sample" />

Field f will not be diplayed, but it will be sent in the request when the form is submitted.
And using method GET or POST will both yield the expected results.

Cheers and happy coding!

-MRB
 
Share this answer
 
Comments
Wild-Programmer 6-Apr-11 9:16am    
My 5+ :)
Thanks to both of you. Good replies.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900