ASP Net Center.com
ASP Tutorials & Basics
Introduction
Variables & Arrays
Sub & Functions
If Statements
Case Statements
Loop Statements
Date Objects
Form Processing
Text File Objects
Database Access
Adding Record
Updating Record
Deleting Record
Virtual Includes
Cookies
E-mail
Server Variables
Creating Login Page

Processing forms using ASP

You can process HTML forms using these two powerful ASP objects, Response and Request.  Response outputs the value to a page and Request retrieves values from an object.  Take a look at the following example:
<form name=”userForm” method=”post” action=”userForm.asp”>
  Enter a user name: <input type=”text” name=”userName” size=”20”>
  Enter a password: <input type=”password” name=”password” size=”20”>
  <inpute type=”submit” name=”submit” value=”Send”>
</form>
Result

Enter a user name:

Enter a password:

We just created HTML form and tell the browser to process the form using the file "userForm.asp".  The following is userForm.asp file that writes the values from the form.
<html>
<head>
<title>Process form Info</title>
</head>
<body>
You have typed the user name <%=Request.Form("userName")%> and the password <%=Request.Form("password")%>.
</body>
</html>
Type something in the text boxes and hit submit button to see the result of this example.  What you will see is the result of this code.   The form will pass the information to userForm.asp file, which then will use the power of Request to write this information.

Form Processing Example 2

You can store value retrieved from form into variables in order to use these value whatever way you want.  Take a look these at this example which is little bit more complex then previous one.
<html>
<head>
<title>Form Example 2</title>
</head>
<body>
<p><b>This example process basic form elements</b>
<form method="POST" action="formProcess.asp">
<p>Your name: <input type="text" name="Name" size="20"><br>
Status: <input type="radio" value="Customer" name="status">Customer   <input type="radio" name="status" value="Visitor">Visitor<br>
Do you own any of these trucks:<br>
<input type="checkbox" name="truck" value="Land Cruiser">Land Cruiser<br>
<input type="checkbox" name="truck" value="Sequoia">Sequoia<br>
<input TYPE="checkbox" name="truck" value="4Runner">4Runner<br>
<input TYPE="checkbox" name="truck" value="Highlander">Highlander<br>
<input TYPE="checkbox" name="truck" value="Tundra Access Cab">Tundra Access Cab<br>
Car of Choice:<select size="1" name="product">
<option value="MR2 Spyder">MR2 Spyder</option>
<option value="Celica">Celica</option>
<option value="Matrix">Matrix</option>
<option value="Avalon">Avalon</option>
<option value="Camry">Camry</option>
<option value="Corolla">Corolla</option>
<option value="Echo">Echo</option>
<option value="Prius">Prius</option>
<option value="RAV4 EV">RAV4 EV</option>
</select><br>
Enter some general comments about what you think about Toyota cars:<br>
<textarea rows="5" name="Comments" cols="50"></textarea><br>
<align="center"><input type="submit" value="Submit" name="submit"><br>
</form>
</body>
</html>
Result of the above code
Form Example 2

This example process basic form elements

Your name:
Status: Customer   Visitor
Do you own any of these trucks:
Land Cruiser
Sequoia
4Runner
Highlander
Tundra Access Cab
Car of Choice:
Any comments about Toyota cars:


Code for formProcess.asp
<html>
<head>
<title>Result of your information</title>
</head>
<body>
<%
dim name, status, truck, car, comments
name=Request.Form("Name")
status=Request.Form("status")
car=Request.Form("car")
comments=Request.Form("comments")
truck=Request.Form("truck")
%>
Your name: <b><%=name%></b><br>
Status: <b><%=status%></b><br>
Your favourite car is: <b><%=car%></b><br>
You currently own these trucks:<b> <%=truck%></b><br>
Your comments about Toyota products:<b><%=comments%></b>
</body>
</html>
Type some information into the form elements and hit submit to see the code in action.

Loops File Objects