ASP Forms
and User Input
The Request.QueryString and Request.Form commands are used to retrieve information from forms, such as user input.
Try It Yourself - Examples
User Input
The Request object can be used to retrieve user information from forms.
HTML Form Example
User input can be retrieved using the Request.QueryString or Request.Form commands.
Request.QueryString
The Request.QueryString command is used to collect values from forms using method="get".
Information sent from a form with the GET method is visible to everyone (it appears in the browser's address bar) and has limits on the amount of information to send.
If the user enters "Bill" and "Gates" in the HTML form above, the URL sent to the server might look like this:
Assuming the "simpleform.asp" file contains the following ASP script:
The browser will display the body of the document as follows:
Request.Form
The Request.Form command is used to collect values from forms using 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 the user enters "Bill" and "Gates" in the HTML form above, the URL sent to the server might look like this:
Assuming the "simpleform.asp" file contains the following ASP script:
The browser will display the body of the document as follows:
Form Validation
Whenever possible, try to validate user input on the browser (using client-side scripts). Browser validation is faster and reduces server load.
If user input will be saved to a database, you should consider using server-side validation. A good way to validate forms on the server side is to send the (validated) form back to the form page instead of redirecting to a different page. Users can then receive error messages on the same page, making it easier for them to spot errors.