Go to: Articles List

For HTML Forms, Should I use GET or POST?

We are referring to the method of an HTML form, example:

<form name=form1 action=thiswebpage.asp METHOD=POST>

The difference... By setting GET as the method of the form you are telling the web server to place the contents of the form you are submitting on the querystring (URL). An example of this is:

http://www.yoursite.com/webdir/thiswebpage.asp?
name=Joe+Johnson&age=50&occ=12&acclevel=7


The can get very long, depending on the size of your form. The advantage to using this is that you can easily debug your application by just looking at the url. The disadvantage is that it doesn't look professional (in my opinion), also it reveals information to the user that you might not want them to see. Another disadvantage is that it exposes your site to someone changing the values on the querystring.

POST... is the best solution (in my opinion). It places the contents of the HTML form in the HTTP header of the action document. Therefore it is not revealed to the user on the querystring. The advantages to using POST is that the form contents are not on the querystring, therefore making it look more professional. The disadvantage is that you will not see the form contents on the querystring and therefore would have to print out the contents of the variable on the action page to see if they are correct.

My recommendation... use POST as your default method. Use GET when you are having problems debugging your code and need to see the values passed. Although a better way still instead of resorting to using the GET method is just to print out your variables from your action page. The reason this is better is because if you change from POST to GET you will have to change your ASP code from Request.Form to Request.QueryString.