Please visit our sponsors !
ASP Forms and User Input
You can get form information with the Request.QueryString command
and the Request.Form command.
Examples
A form that uses the
"get" method
This example demonstrates how to interact with the user, with the Request.QueryString
command.
A form that uses the
"post" method
This example demonstrates how to interact with the user, with the Request.Form command.
A form with radio buttons
This example demonstrates how to interact with the user, through radio buttons,
with the Request.Form command.
User Input
To get information from forms, you can use the Request Object.
A simple form example:
<form method="get" action="../pg.asp">
First Name: <input type="text" name="fname"><br>
Last Name: <input type="text" name="lname"><br>
<input type="submit" value="Send">
</form>
|
There are two ways to get form information: The Request.QueryString command
and the Request.Form command.
Request.QueryString
The Request.QueryString command collects the values in a form as text.
Information sent from a form with the GET method is visible to everybody (in the address field).
Remember that the GET method limits the amount of information to send.
If a user typed "Bill" and "Gates" in the form example
above, the url sent to the server would look like
this:
http://www.w3schools.com/pg.asp?fname=Bill&lname=Gates
|
The ASP file "pg.asp" contains the following script:
<body>
Welcome
<%
response.write(request.querystring("fname"))
response.write(" ")
response.write(request.querystring("lname"))
%>
</body>
|
The example above writes this into the body of a document:
Request.Form
To collect the values in a form with the POST method, use the Request.Form
command.
Information sent from a form with the POST method is invisible to others. The
POST method has no limits, you can send a large amount of information.
If a user typed "Bill" and "Gates" in the form example
above, the url sent to the server would look like
this:
http://www.w3schools.com/pg.asp
|
The ASP file "pg.asp" contains the following script:
<body>
Welcome
<%
response.write(request.form("fname"))
response.write(" ")
response.write(request.form("lname"))
%>
</body>
|
The example above writes this into the body of a document:
Form Validation
The form input should be validated on the browser, by client side scripts.
Browser validation has a faster response time, and reduces the load on the server.
You should consider using server validation if the input from a form is
inserted into a database. A good way to validate the form on a server is to post
the form into itself, instead of jumping to a different page. The user will then
get the error messages on the same page as the form. This makes it easier to
discover the error.
Jump to: Top of Page
or HOME or
Printer friendly page
Search W3Schools:
What Others Say About Us
Does the world know about us? Check out these places:
Dogpile
Alta Vista
MSN
Google
Excite
Lycos
Yahoo
Ask Jeeves
We Help You For Free. You Can Help Us!
W3Schools is for training only. We do not warrant its correctness or its fitness for use.
The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our
terms of use and
privacy policy.
Copyright 1999-2002 by Refsnes Data. All Rights Reserved
|