ASP FormCollection


Request 对象参考手册Complete Request Object Reference Manual

The Form collection is used to retrieve the values of form elements from a form that uses the POST method.

Syntax

Request.Form(element)[(index)|.Count]

Parameters Description
element Required. The name of the form element from which the collection retrieves a value.
index Optional. Specifies one of multiple values for a parameter. From 1 to Request.Form(parameter).Count.


Examples

Example 1

You can loop through all the values in the form request. Suppose the user filled out the form by specifying two values for the color element - Blue and Green - you can retrieve these values like this:

<% for i=1 to Request.Form("color").Count
  Response.Write(Request.Form("color")(i) & "<br>")
next
%>

Output:

Blue
Green

Example 2

Please take a close look at this form:

<form action="submit.html" method="post">
<p>First name: <input name="firstname"></p>
<p>Last name: <input name="lastname"></p>
<p>Your favorite color:
<select name="color">
<option>Blue</option>
<option>Green</option>
<option>Red</option>
<option>Yellow</option>
<option>Pink</option>
</select>
</p>
<p><input type="submit"></p>
</form>

Suppose the following request is sent:

firstname=John&lastname=Dove&color=Red

Now, we can use the information in the form through a script:

Hi, <%=Request.Form("firstname")%>. 
Your favorite color is <%=Request.Form("color")%>.

Output:

Hi, John. Your favorite color is Red.

If you do not specify the element to display:

Form data is: <%=Request.Form%> 

Then the output will become like this:

Form data is: firstname=John&lastname=Dove&color=Red


Request 对象参考手册Complete Request Object Reference Manual Other Extensions