GET and POST methods and how to get info from them

There are two ways we may get info from users by using a form: GET and POST methods. Additionally, GET method may be used for other porpoises as a regular link. Let´s check both methods

POST method

This method will be indicated in the form we are using to get information from user as shown in the example bellow
 

<form method="POST" action=""> 
Your name<BR>
<input type=text name=thename size=15><BR>
Your age<BR>
<input type=text name=theage size=15><BR>
<input type=submit  value="Send info">
</form> 
Your name

Your age

When submitting the form we will visit the URL bellow (will be different when using GET method):

http://www.asptutorial. info/sscript/getandpostgetinfo.asp
When getting information from the form in the response page we will use Request.Form command
 
 
Code Output
<% =Request.form %> thename=John&theage=30
<% =Request.form ("thename") %> John
<% =Request.form ("theage") %> 30
<% 
Theage=Request.form ("theage") 
Thename=Request.form ("thename") 
Response.write("Hi " & Thename & ", I know you are " & Theage & " years old")
%>
Hi John, I know you are 30 years old

 

GET method

This method may be used exactly as in the example above, but the URL we will visit after submission will be diferent.

In the example bellow we have replace the word "POST" and "GET" has been written instead.
 

<form method="GET" action="getandpostgetinfo.asp"> 
Your name<BR>
<input type=text name=thename size=15><BR>
Your age<BR>
<input type=text name=theage size=15><BR>
<input type=submit  value="Send info">
</form> 
Your name

Your age

When submitting the form we will visit the URL bellow (will be different when using GET method):

http://www.asptutorial. info/sscript/getandpostgetinfo.asp?thename=John&theage=30
When getting information from the form in the response page we will use Request.Querystring command.
 
 
Code Output
<% =Request.Querystring %> thename=John&theage=30
<% =Request.Querystring ("thename") %> John
<% =Request.Querystring ("theage") %> 30
<% 
Theage=Request.Querystring ("theage") 
Thename=Request.Querystring ("thename") 
Response.write("Hi " & Thename & ", I know you are " & Theage & " years old")
%>
Hi John, I know you are 30 years old

Get method may be used for additonal porpoises. In the example bellow it is shown data in different ways depending on request.querystring values obtained from the the url visited.
 

Getandpostexample.asp 
<html>
<body bgcolor=FFFFFF>
<pre>
<b>Information  about my friends</b>

<% if request.querystring="showall" then %>
Anna
 From London. Student
Paolo
 From Roma. Student
Andoni
 From Donosti. Student

<a href=Getandpostexample.asp>Hide data</a>
<% else %>

<% if request.querystring("name")="Anna" then%>
Anna
 From London. Student 
<% else %>
<a href=Getandpostexample.asp?name=Anna>Anna</a>
<% end if %>
<% if request.querystring("name")="Paolo" then%>
Paolo
 From Roma. Student
<% else %>
<a href=Getandpostexample.asp?name=Paolo>Paolo</a>
<% end if %>
<% if request.querystring("name")="Andoni" then%>
Paolo
 From Roma. Student
<% else %>
<a href=Getandpostexample.asp?name=Andoni>Andoni</a>
<% end if %>

<a href=Getandpostexample.asp?showall>Show all data</a>

<% end if %>
</pre>
<HR>
Please visit my sponsors
</body>
</html>


AspTutorial.info.