ASP Form collection
Form collection is used to obtain a form using the POST method from form element values.
grammar
Request.Form(element)[(index)|.Count]
参数 | 描述 |
---|---|
element | 必需。表单元素的名称,此集合从中取回值。 |
index | 可选。规定一个参数的多个值中的一个。从 1 到 Request.Form(parameter).Count。 |
Examples
Example 1
You can loop through all the values in a form request. Suppose that you specify two values for the color elements to fill out the forms - Blue and Green - so that you can retrieve these values:
<%
for i=1 to Request.Form("color").Count
Response.Write(Request.Form("color")(i) & "<br>")
next
%>
Response.Write(Request.Form("color")(i) & "<br>")
next
%>
Output:
Blue
Green
Green
Example 2
Please carefully 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>
<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, sent the following request:
firstname=John&lastname=Dove&color=Red
We can now be used by a script information in the form of:
Hi, <%=Request.Form("firstname")%>.
Your favorite color is <%=Request.Form("color")%>.
Your favorite color is <%=Request.Form("color")%>.
Output:
Hi, John. Your favorite color is Red.
If you do not specify the element to be displayed:
Form data is: <%=Request.Form%>
Then the output will be like this:
Form data is: firstname=John&lastname=Dove&color=Red
Complete Request Object Reference