HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to Classic ASPVariablesStringsConditions (If / Select Case)Loops (For / Do While)Form and Request
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
✍️ Text & Number
🔁 Condition & Loop
🧩 Functions & Forms
Classic ASP›Form and Request

Form and Request

Reading data coming from the form with Request and using it securely.

Simple enough for a 5-year-old to understand

Read form data

Values submitted by the user via the form are read using Request.Form. Values in the address bar are retrieved using Request.QueryString.

Example code
1
Dim name
2
name = Request.Form("name")
Gets the value of the field in the form.
Output / InputGets the value of the field in the form.
3
Response.Write "Hello " & name
Writes the incoming value.
Output / InputWrites the incoming value.
Output / Input
💡 Hint: The name attribute of the form field must match this name.

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (1 left)

1.Which one reads the data submitted by the form?

About this topic

In ASP, form data is read via the request object. If the submission method is POST, the data is in the form collection; if appended to the URL, it is in the query string collection. The two collections represent different sources.

It is also possible to read data directly by name without specifying a collection, but in this case, the server scans several collections in order. This obscures the source and allows an attacker to pass a value from an unexpected collection.

Form data is always under user control and is untrusted under any circumstances. Client-side validation can be bypassed; re-checking on the server side is mandatory. Embedding data directly into the query also leads to the most well-known security vulnerability.

What you will learn

  • Form and query string collections
  • Submission methods
  • Server-side validation
  • Query injection risk
  • Output escaping

Who is this for?

  • ASP developers processing forms
  • Security reviewers
  • Those hardening legacy pages

When to use?

Every value from the user must be retrieved by explicitly specifying which collection it will be read from and validated before use.

In database queries, values should never be embedded via string concatenation, but passed using parameterized commands.

Common mistakes

Wrong

<%
Option Explicit
Dim ad, sorgu, kayitlar
ad = Request("ad")
sorgu = "SELECT * FROM uyeler WHERE ad = '" & ad & "'"
Set kayitlar = baglanti.Execute(sorgu)
%>

Because user input is embedded directly into the query, a value containing quotes can alter the query structure and lead to reading or deleting the entire table. This is a query injection attack and is completely prevented by passing values as parameters.

Correct

<%
Option Explicit
Dim ad, komut, kayitlar
ad = Request.Form("ad")
Set komut = Server.CreateObject("ADODB.Command")
komut.ActiveConnection = baglanti
komut.CommandText = "SELECT * FROM uyeler WHERE ad = ?"
komut.Parameters.Append komut.CreateParameter("p1", 200, 1, 50, ad)
Set kayitlar = komut.Execute()
%>

Wrong

<%
Option Explicit
Dim yas
yas = Request.Form("yas")
If yas > 18 Then
  Response.Write "adult"
End If
%>

Form values are always text; when comparing with a number, VBScript attempts a conversion, and if the field is empty or contains letters, it yields unexpected results or throws an error. The value must be validated as numeric and explicitly converted.

Correct

<%
Option Explicit
Dim yas
yas = Request.Form("yas")
If IsNumeric(yas) Then
  If CInt(yas) > 18 Then
    Response.Write "adult"
  End If
Else
  Response.Write "Invalid age"
End If
%>

Wrong

<%
Option Explicit
Dim ad
ad = Request.Form("ad")
If ad = "" Then
  Response.Write "Name is required"
End If
Response.Write "Welcome " & ad
%>

The validation prints an error message but does not stop the flow; execution continues even in the invalid state. Also, since the input is printed without escaping, there is a script injection risk. If validation fails, execution must be terminated and output must always be escaped.

Correct

<%
Option Explicit
Dim ad
ad = Trim(Request.Form("ad"))
If ad = "" Then
  Response.Write "Name is required"
  Response.End
End If
Response.Write "Welcome " & Server.HTMLEncode(ad)
%>

Frequently asked questions

What is the difference between the two collections?

One carries form fields submitted in the body, while the other carries values appended to the URL. Explicitly writing which one you are reading both documents intent and prevents values from coming from an unexpected source.

How is file upload performed?

Classic ASP lacks built-in support; you must manually parse the binary request body or use a component. Checking the type and size of the uploaded file and rejecting executable extensions is mandatory.

How to detect an empty field?

An unsubmitted field returns an empty string, not an undefined value. Therefore, trimming whitespace and comparing it to an empty string is the correct check; numeric fields also require a numeric check.

Summary

The collection name must always be written explicitly.

Form data is always text.

Server-side validation is mandatory.

Queries are executed with parameterized commands.

Output must be escaped for HTML.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code