๐ Classic ASP โ Forms โ Handle User Input with Request.Form and Request.QueryString
๐งฒ Introduction โ What Are Forms in Classic ASP?
Forms in Classic ASP enable your web pages to collect user input using HTML controls and then process the submitted data on the server. ASP makes this possible using the Request
object, specifically Request.Form
(POST method) and Request.QueryString
(GET method).
๐ฏ In this guide, youโll learn:
- How to create HTML forms in Classic ASP
- Use
Request.Form
andRequest.QueryString
to access data - Process input with VBScript
- Handle validation and display output
๐๏ธ HTML Form with POST Method
<form method="post" action="submit.asp">
Name: <input type="text" name="username"><br>
Age: <input type="text" name="age"><br>
<input type="submit" value="Submit">
</form>
๐ This form submits user input to submit.asp
via POST.
๐ฅ Access Form Data with Request.Form
<%
Dim name, age
name = Request.Form("username")
age = Request.Form("age")
Response.Write "Welcome, " & name & "! You are " & age & " years old."
%>
๐งช Output Example (user enters John, 30):Welcome, John! You are 30 years old.
๐ Using GET Method with Request.QueryString
<form method="get" action="submit.asp">
Search: <input type="text" name="keyword">
<input type="submit" value="Go">
</form>
<%
Dim keyword
keyword = Request.QueryString("keyword")
Response.Write "Search term: " & keyword
%>
๐งช URL after submit:submit.asp?keyword=asp
๐งช Output: Search term: asp
โ Validating Input
<%
Dim email
email = Trim(Request.Form("email"))
If email = "" Then
Response.Write "Email is required."
Else
Response.Write "Thanks! Email submitted: " & email
End If
%>
โ Example โ Full Form Flow
๐ form.asp
(HTML + POST)
<form method="post" action="submit.asp">
Email: <input type="text" name="email"><br>
Password: <input type="password" name="password"><br>
<input type="submit" value="Login">
</form>
๐ submit.asp
(ASP Processing)
<%
Dim email, password
email = Request.Form("email")
password = Request.Form("password")
If email = "" Or password = "" Then
Response.Write "Both fields are required."
Else
Response.Write "Logged in as: " & email
End If
%>
๐ Loop Through All Form Fields
<%
Dim field
For Each field In Request.Form
Response.Write field & ": " & Request.Form(field) & "<br>"
Next
%>
๐งช Output:
Displays each form field and its value.
๐งฉ Hidden Fields
<input type="hidden" name="user_id" value="12345">
๐ Used to pass data silently with the form.
๐ Best Practices for Forms in Classic ASP
โ Do:
- Sanitize inputs using
Trim()
or regex - Use POST for sensitive data (passwords, logins)
- Handle empty inputs and display messages
โ Avoid:
- Using GET for passwords or sensitive fields
- Trusting user input without validation
- Overusing global variables for form data
๐ Summary โ Recap & Next Steps
Classic ASP forms let users interact with your website and submit data to the server for processing. With Request.Form
and Request.QueryString
, you can access form fields and customize the user experience.
๐ Key Takeaways:
- Use
<form method="post">
to send data securely - Access form fields using
Request.Form("fieldname")
- Always validate and sanitize user input
โ๏ธ Real-world Use Cases:
- User login or registration forms
- Feedback, survey, or contact forms
- Admin panels or data entry tools
โ FAQs โ Classic ASP Forms
โ Whatโs the difference between Request.Form
and Request.QueryString
?
โ
Request.Form
reads data from POST requests, while Request.QueryString
reads from the URL (GET requests).
โ Can I combine Request.Form
and Request.QueryString
?
โ
Yes. Use Request("fieldname")
to check both methods at once.
โ How do I prevent blank fields from being submitted?
โ
Use VBScript to check:
If Trim(Request.Form("field")) = "" Then ...
Share Now :