Forms
Retrieving User Input in ASP
ASP provides the Request.QueryString and Request.Form objects to collect input entered by users in HTML forms.
More Examples
Form using method="get"
This demonstrates how to interact with user input using the Request.QueryString object.
Form using method="post"
This shows how to handle user input using the Request.Form object.
Form with Radio Buttons
This example explains how to retrieve selected radio button values using Request.Form.
User Input in ASP
The Request object is used to gather information submitted by users through forms.
User input can be accessed using:
Request.QueryString
Request.Form
The method used depends on whether the form is submitted using GET or POST.
Request.QueryString
The Request.QueryString object retrieves form values submitted using the GET method.
Data sent using GET is visible in the browser’s address bar
There is a limit on the amount of data that can be sent
Example HTML Form (GET):
If the user enters Bill and Gates, the URL sent to the server will be:
https://www.w3schools.com/simpleform.asp?fname=Bill&lname=Gates
ASP Code (simpleform.asp):
Welcome <% Response.Write(Request.QueryString("fname")) Response.Write(" " & Request.QueryString("lname")) %>
Output:
Welcome Bill Gates
Request.Form
The Request.Form object is used to retrieve values submitted using the POST method.
POST data is not visible in the browser address bar
There is no limit on the amount of data sent
Example HTML Form (POST):
If the user submits the form, the URL will look like this:
https://www.w3schools.com/simpleform.asp
ASP Code (simpleform.asp):
Welcome <% Response.Write(Request.Form("fname")) Response.Write(" " & Request.Form("lname")) %>
Output:
Welcome Bill Gates
Form Validation
User input should be validated on the client side whenever possible using browser-based scripts. This improves performance and reduces server load.
However, server-side validation is important when:
Data is stored in a database
Security is a concern
A good server-side validation technique is to post the form to the same page, so any error messages can be displayed alongside the form. This makes errors easier for users to identify and correct.