Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

ASP Forms

ASP Forms and User Input


The Request.QueryString and Request.Form commands are used to retrieve information from a form, such as user input.


Try it - Example

Using a Form with method="get"
This example demonstrates how to interact with users using the Request.QueryString command.

Using a Form with method="post"
This example demonstrates how to interact with users using the Request.Form command.

Using a Form with Radio Buttons
This example demonstrates how to interact with users through radio buttons using the Request.Form command.


User input

The Request object can be used to retrieve user information from a form.

HTML Form Example

First Name:

Last Name:

User input can be retrieved through the Request.QueryString or Request.Form commands.


Request.QueryString

The Request.QueryString command is used to collect values from a form that uses method="get".

Information sent from a form using the GET method is visible to all users (it appears in the browser's address bar), and there is a limit on the amount of information that can be sent.

If a user enters "Bill" and "Gates" in the HTML form above, the URL sent to the server will look something like this:

http://www.w3cschool.cc/simpleform.asp?fname=Bill&lname=Gates

Suppose the "simpleform.asp" file contains the following ASP script:

Welcome

<%

response.write(request.querystring("fname"))

response.write(" " & request.querystring("lname"))

%>

The browser will display the body section of the document as follows:

Welcome Bill Gates


Request.Form

The Request.Form command is used to collect values from a form that uses method="post".

Information sent from a form using the POST method is invisible to users, and there is no limit on the amount of information that can be sent.

If a user enters "Bill" and "Gates" in the HTML form above, the URL sent to the server will look something like this:

http://www.w3cschool.cc/simpleform.asp

Suppose the "simpleform.asp" file contains the following ASP script:

Welcome

<%

response.write(request.form("fname"))

response.write(" " & request.form("lname"))

%>

The browser will display the body section of the document as follows:

Welcome Bill Gates


Form Validation

Whenever possible, validate user input in the browser (through client-side scripts). Browser validation is faster and can reduce the load on the server.

If user input is saved to a database, you should consider using server-side validation. A good way to validate a form on the server is to send the (validated) form back to the form page instead of redirecting to a different page. The user can then get error messages on the same page. This makes it easier for users to find mistakes.