๐Ÿ’ป Classic ASP โ€“ Logic & Scripting
Estimated reading: 4 minutes 35 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 :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

๐Ÿ“‹ Classic ASP โ€“ Forms

Or Copy Link

CONTENTS
Scroll to Top