ASP FormsandUser Input
The Request.QueryString and Request.Form commands are used to retrieve information from a form, such as user input.
Try it Yourself - Examples
Form using method="get"
This example demonstrates how to interact with users using the Request.QueryString command.
Form using method="post"
This example demonstrates how to interact with users using the Request.Form command.
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: <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 using 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 are also limits on the amount of information that can be sent.
If the user enters "Bill" and "Gates" in the HTML form above, the URL sent to the server would look something like this:
Assume the "simpleform.asp" file contains the following ASP script:
Welcome
<%
response.write(request.querystring("fname"))
response.write(" " & request.querystring("lname"))
%>
</body>
The browser will display the body section of the document as follows:
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 not visible to users, and there is no limit on the amount of information that can be sent.
If the user enters "Bill" and "Gates" in the HTML form above, the URL sent to the server would look something like this:
Assume the "simpleform.asp" file contains the following ASP script:
Welcome
<%
response.write(request.form("fname"))
response.write(" " & request.form("lname"))
%>
</body>
The browser will display the body section of the document as follows:
Form Validation
Whenever possible, validate user input in the browser (through client-side scripts). Browser validation is faster and reduces the server load.
If user input is to be saved to a database, you should consider using server-side validation. A good way to validate a form on the server is to post the form (with validation) back to the form page instead of moving to a different page. The user can then see the error messages on the same page. This makes it easier for users to find errors.
Other Extensions