๐Ÿ’ป Classic ASP โ€“ Logic & Scripting
Estimated reading: 4 minutes 444 views

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 and Request.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 :
Share

๐Ÿ“‹ Classic ASP โ€“ Forms

Or Copy Link

CONTENTS
Scroll to Top