Form collection
Note that because this ASP example tutorial is about the form code, to save trouble, I won’t take screenshots! Everyone can test the instance execution results by themselves!
A simple application of Form collection
This example demonstrates how the Form collection retrieves values from the form. This form uses the POST method, which means that the information sent is invisible to the user, and there is no limit on the amount of information sent (large amounts can be sent).
This sample code is as follows:
The following is the quoted content:
<html>
<body>
<form action=/example/aspe/demo_aspe_simpleform1.asp method=post>
First name:
<input type=text name=fname value=Donald />
<br />
Last name:
<input type=text name=lname value=Duck />
<br />
<input type=submit value=Submit />
</form>
<%
Response.Write(Request.Form)
%>
</body>
</html>
How to use information from forms
This example demonstrates how to use information retrieved from a form. We used the Form collection. The form uses the POST method.
This sample code is as follows:
The following is the quoted content:
<html>
<body>
<form action=/example/aspe/demo_aspe_simpleform.asp method=post>
Your name: <input type=text name=fname size=20 />
<input type=submit value=submit/>
</form>
<%
dim fname
fname=Request.Form(fname)
If fname<> Then
Response.Write(Hello! & fname &!<br />)
Response.Write(How are you doing today?)
End If
%>
</body>
</html>
More information from the form
This example demonstrates what information the Form collection will contain if several input fields use the same name. It will show how to separate these identical names. It also shows how to use the count keyword to count the name attribute. This form uses the POST method.
This sample code is as follows:
The following is the quoted content:
<html>
<body>
<form action=/example/aspe/demo_aspe_form2.asp method=post>
First name:
<input type=text name=name value=Donald />
<br />
Last name:
<input type=text name=name value=Duck />
<br />
<input type=submit value=Submit />
</form>
<hr />
<p>Information from the form above:</p>
<%
If Request.Form(name)<> Then
Response.Write(<p>)
Response.Write(name= & Request.Form(name))
Response.Write(</p><p>)
Response.Write(Number of name attributes:)
Response.Write(Request.Form(name).Count)
Response.Write(</p><p>)
Response.Write(First name= & Request.Form(name)(1))
Response.Write(</p><p>)
Response.Write(Last name= & Request.Form(name)(2))
Response.Write(</p>)
End if
%>
</body>
</html>
form with radio buttons
This example demonstrates how to use the Form collection to interact with the user through radio buttons. This form uses the POST method.
This sample code is as follows:
The following is the quoted content:
<html>
<%
dim cars
cars=Request.Form(cars)
%>
<body>
<form action=/example/aspe/demo_aspe_radiob.asp method=post>
<p>Please select your favorite car:</p>
<input type=radio name=cars
<%if cars=Volvo then Response.Write(checked)%>
value=Volvo>Volvo</input>
<br />
<input type=radio name=cars
<%if cars=Saab then Response.Write(checked)%>
value=Saab>Saab</input>
<br />
<input type=radio name=cars
<%if cars=BMW then Response.Write(checked)%>
value=BMW>BMW</input>
<br /><br />
<input type=submit value=submit/>
</form>
<%
if cars<> then
Response.Write(<p>The car you like is & cars & </p>)
end if
%>
</body>
</html>
form with check buttons
This example demonstrates how to use the Form collection to interact with the user through check buttons. This form uses the POST method.
This sample code is as follows:
The following is the quoted content:
<html>
<body>
<%
fruits=Request.Form(fruits)
%>
<form action=/example/aspe/demo_aspe_checkboxes.asp method=post>
<p>What fruits do you like:</p>
<input type=checkbox name=fruits value=Apples
<%if instr(fruits,Apple) then Response.Write(checked)%>>
Apple
<br>
<input type=checkbox name=fruits value=Oranges
<%if instr(fruits,Oranges) then Response.Write(checked)%>>
Orange
<br>
<input type=checkbox name=fruits value=Bananas
<%if instr(fruits,Banana) then Response.Write(checked)%>>
Banana
<br>
<input type=submit value=submit>
</form>
<%
if fruits<> then%>
<p>You like: <%Response.Write(fruits)%></p>
<%end if
%>
</body>
</html>