ASP Forms and User Input
The Request.QueryString and Request.Form commands are used to retrieve user input from forms.
 |
Try it Yourself - Examples |
A form with method="get"
How to interact with the user, with the Request.QueryString command.
A form with method="post"
How to interact with the user, with the Request.Form command.
A form with radio buttons
How to interact with the user, through radio buttons, with the Request.Form command.
User Input
The Request object can be used to retrieve user information from forms.
Example HTML form
<form method="get" action="simpleform.asp">
First Name: <input type="text" name="fname" /><br />
Last Name: <input type="text" name="lname" /><br /><br />
<input type="submit" value="Submit" />
</form> |
User input can be retrieved with the Request.QueryString or Request.Form command.
Request.QueryString
The Request.QueryString command is used to collect values in a form with method="get".
Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar)
and has limits on the amount of information to send.
If a user typed "Bill" and "Gates" in the HTML form above, the URL sent to the server would look like this:
| http://www.w3schools.com/simpleform.asp?fname=Bill&lname=Gates |
Assume that "simpleform.asp" contains the following ASP script:
<body>
Welcome
<%
response.write(request.querystring("fname"))
response.write(" " & request.querystring("lname"))
%>
</body> |
The browser will display the following in the body of the document:
Request.Form
The Request.Form
command is used to collect values in a form with method="post".
Information sent from a form with the POST method
is invisible to others and has no limits on the amount of information to send.
If a user typed "Bill" and "Gates" in the HTML form
above, the URL sent to the server would look like this:
| http://www.w3schools.com/simpleform.asp |
Assume that "simpleform.asp" contains the following ASP script:
<body>
Welcome
<%
response.write(request.form("fname"))
response.write(" " & request.form("lname"))
%>
</body> |
The browser will display the following in the body of the document:
Form Validation
User input should be validated on the browser whenever possible (by client scripts).
Browser validation is faster and reduces the server load.
You should consider server validation if the user input will be
inserted into a database. A good way to validate a form on the server is to post
the form to 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.

Need an easy way to get data into XML, or transform XML to another format?
MapForce lets you map XML data to/from any combination of XML, database, flat file, Excel 2007, XBRL, or Web services data.
Then it transforms data instantly or auto-generates royalty-free data integration code for recurrent conversions.
Download a free, fully functional 30-day trial to experience the following features:
- Easy-to-use, graphical data mapping interface
- Instant data transformation
- XSLT 1.0/2.0 and XQuery code generation
- Java, C#, and C++ code generation
- Advanced data processing functions
- Support for all major relational databases including SQL Server, IBM DB2, Oracle, and more
- Visual Studio & Eclipse integration
Download a fully-functional trial today!
|
|
|
|