Synopsis
Request.Form(Element)[(Index)|.Count] |
Read only
This collection contains the values of the different elements of a form that one sent with the POST method
(without any special encoding, i.e. the attribute enctype of the <FORM> tag is not
set or is set to application/x-www-form-urlencoded).
Warning! This collection is not able to handle file uploads, and more generally, it is not able to handle
multipart encoded forms (i.e. forms where enctype is set to multipart/form-data). One must
use a dedicated librairy.
Element is the only mandatory parameter.
Use of the collection
The elements
It is the most direct way to access the different form elements. Element is the name used in the form
to designate this element.
|
If the initial form is:
<FORM action="form.asp" method="post">
login: <INPUT type="text" name="login" size="20"><BR>
password: <INPUT type="password" name="password" size="20">
<INPUT type="submit" value="OK">
</FORM>
The collection Request.Form will then contains the following two elements:
Request.Form("login") et Request.Form("password").
|
In VBScript, as for all collections, it is possible to iterate through the collection with a
For Each ... Next loop:
For Each element In Request.Form
Response.Write(element & " = " & Request.Form(element))
Next
|
Multiple-value elements
Some elements can contains several sub-values. For example, this is the case with multiple lists or checkbox areas
in forms (actually, this occurs whenever several elements in a form have the same name). We access these sub-values
thanks to an integer (Index). This integer starts from 1. The attribute Count gives the number
of possible sub-values of an element:
|
Initial form:
<FORM action="form.asp" method="post">
<SELECT name="list" size="10" multiple>
<OPTION value="element_1">element 1</OPTION>
<OPTION value="element_2">element 2</OPTION>
...
</SELECT>
<INPUT type="submit" value="OK">
</FORM>
or:
<FORM action="form.asp" method="post">
<INPUT type="checkbox" name="list" value="element_1"> element 1<BR>
<INPUT type="checkbox" name="list" value="element_2"> element 2<BR>
...
<INPUT type="submit" value="OK">
</FORM>
form.asp :
<%
Response.Write(Request.Form("list").Count & " elements:<BR>")
For i = 1 To Request.Form("list").Count
Response.Write(Request.Form("list")(i) & "<BR>")
Next
%>
If the elements 1, 5 and 13 are selected or checked, we get:
3 elements:
element_1
element_5
element_13
|
Besides, Response.Write(Request.Form) would display a string identical to the query string that would
have been sent if the form were sent with the GET method (see Request.QueryString).
printable format
|