ASP Reading Form Data

Learn how to read data submitted from HTML forms in classic ASP, using Request.Form for POST submissions and Request.QueryString for GET or URL parameters.

Two Ways Data Reaches Your ASP Page

An HTML form sends its data to the server in one of two ways, depending on its method attribute. A form with method="get" appends the field values onto the URL as a query string, while a form with method="post" sends them inside the body of the request, invisible in the address bar. ASP gives you a separate collection for reading each kind, and using the wrong one is one of the most common beginner mistakes.

MethodWhere the Data LivesASP Collection to Read It
GETAppended to the URL as a query stringRequest.QueryString
POSTSent in the request bodyRequest.Form

Reading POST Data with Request.Form

Example: Reading a posted signup form

<%
Dim userName, userEmail

If Request.Form("submitted") = "yes" Then
    userName = Request.Form("username")
    userEmail = Request.Form("email")

    Response.Write("Thanks for signing up, " & userName & "!<br>")
    Response.Write("We will send updates to " & userEmail & ".")
End If
%>

<form method="post" action="signup.asp">
    <input type="hidden" name="submitted" value="yes">
    <input type="text" name="username" placeholder="Your name">
    <input type="text" name="email" placeholder="Your email">
    <input type="submit" value="Sign Up">
</form>

Reading GET Data with Request.QueryString

Example: Reading parameters from the URL

<%
Dim productId, sortOrder

productId = Request.QueryString("id")
sortOrder = Request.QueryString("sort")

Response.Write("Showing product #" & productId & "<br>")
Response.Write("Sorted by: " & sortOrder)
%>

<!-- Visiting product.asp?id=42&sort=price would print: -->
<!-- Showing product #42 -->
<!-- Sorted by: price -->
Note: Request.Form only ever contains data sent in a POST body, and Request.QueryString only ever contains data appended to the URL. If your form uses method="get" but your script reads Request.Form, every field will come back empty — the fix is always to match the collection to the form's actual method attribute.
  • If a field was not submitted at all, Request.Form("field") or Request.QueryString("field") returns an empty string rather than raising an error.
  • It is good practice to check Request.Form("field") <> "" before using a value, in case the visitor left it blank.
  • When a form field can hold more than one value, such as a group of checkboxes sharing the same name, Request.Form("field").Count tells you how many values were submitted.

Example: Reading multiple checkbox values

<%
Dim i, colorCount
colorCount = Request.Form("colors").Count

Response.Write("You selected " & colorCount & " colors:<br>")

For i = 1 To colorCount
    Response.Write(Request.Form("colors")(i) & "<br>")
Next
%>
Note: ASP also lets you write Request("name") without naming a collection at all. It works by searching QueryString, then Form, then Cookies, then ServerVariables until it finds a match, but that extra searching is slower and can pick up the wrong value if two collections share a name. Naming the collection explicitly is clearer and safer.

Exercise: ASP Forms

When an HTML form uses method="post", how does the ASP page read the submitted field values?