2025-04-27 07:49:33 -04:00

164 lines
6.8 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">
<TITLE>Form</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
TempString = navigator.appVersion
if (navigator.appName == "Microsoft Internet Explorer"){
// Check to see if browser is Microsoft
if (TempString.indexOf ("4.") >= 0){
// Check to see if it is IE 4
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
}
else {
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
}
}
else if (navigator.appName == "Netscape") {
// Check to see if browser is Netscape
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
}
else
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
//-->
</script>
<SCRIPT LANGUAGE="VBScript">
<!--
Sub Window_OnLoad()
Dim frmContents
On Error Resume Next
If Not Parent Is Nothing Then
Set frmContents = Parent.Contents
If Not frmContents Is Nothing Then
frmContents.Window.TOCSynch_Click
End If
End If
End Sub
//--></SCRIPT><META NAME="DESCRIPTION" CONTENT="Internet Information Services reference information">
<META HTTP-EQUIV="PICS-Label" CONTENT='(PICS-1.1 "<http://www.rsac.org/ratingsv01.html>" l comment "RSACi North America Server" by "inet@microsoft.com <mailto:inet@microsoft.com>" r (n 0 s 0 v 0 l 0))'>
<META NAME="MS.LOCALE" CONTENT="EN-US">
<META NAME="MS-IT-LOC" Content="Internet Information Services">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H4><A NAME="_form"></A><SUP></SUP>Form</H4>
<P>The <B>Form </B>collection retrieves the values of form elements posted to the HTTP request body, with a form using the POST method.</P>
<H6>Syntax</H6>
<P><B>Request.Form(</B><I>element</I><B>)</B>[<B>(</B><I>index</I><B>)</B>|<B>.Count</B>]</P>
<P>&nbsp;</P>
<H6>Parameters</H6>
<DL>
<DT><I>element</I></DT>
<DD>The name of the form element from which the collection is to retrieve values.<BR>
</DD>
<DT><I>index</I></DT>
<DD>An optional parameter that enables you to access one of multiple values for a parameter. It can be any integer in the range 1 to <B>Request.Form(</B><I>parameter</I><B>).Count</B>.</DD>
</DL>
<H6>Remarks</H6>
<P>The <B>Form </B>collection is indexed by the names of the parameters in the request body. The value of <B>Request.Form(</B><I>element</I><B>) </B>is an array of all the values of <I>element</I> that occur in the request body. You can determine the number of values of a parameter by calling <B>Request.Form(</B><I>element</I><B>).Count</B>. If a parameter does not have multiple values associated with it, the count is 1. If the parameter is not found, the count is 0.</P>
<P>To reference a single value of a form element that has multiple values, you must specify a value for <I>index</I>. The <I>index </I>parameter may be any number between 1 and <B>Request.Form(</B><I>element</I><B>).Count</B>. If you reference one of multiple form parameters without specifying a value for <I>index</I>, the data is returned as a comma-delimited string.</P>
<P>When you use parameters with <B>Request.Form</B>, the Web server parses the HTTP request body and returns the specified data. If your application requires unparsed data from the form, you can access it by calling <B>Request.Form</B> without any parameters.</P>
<P><span class=le><B>Note&nbsp; </B></span>When using ASP and posting large amounts of data beyond 100 kilobytes, <B>Request.Form</B> cannot be used. If your application requires posting data greater than this limit, a component can be written which uses the <B>Request.BinaryRead</B> method.</P>
<P>You can iterate through all the data values in a form request. For example, if a user filled out a form by specifying two values - Chocolate and Butterscotch - for the FavoriteFlavor element, you could retrieve those values by using the following script.</P>
<PRE><CODE>&lt;%
For i = 1 To Request.Form("FavoriteFlavor").Count
Response.Write Request.Form("FavoriteFlavor")(i) &amp; "&lt;BR&gt;"
Next
%&gt;
</CODE></PRE>
<P>The preceding script would display the following.</P>
<PRE><CODE>Chocolate
Butterscotch
</CODE></PRE>
<P>You can use this technique to display the parameter name, as shown in the following script:</P>
<PRE><CODE>&lt;%
For i = 1 to Request.Form("FavoriteFlavor").count %&gt;
Request.Form(FavoriteFlavor) = &lt;%= Request.Form("FavoriteFlavor")(i)_
%&gt; &lt;BR&gt;
&lt;% Next %&gt;
</CODE></PRE>
<P>This script displays the following in the browser. </P>
<PRE><CODE>Request.Form(FavoriteFlavor) = Chocolate
Request.Form(FavoriteFlavor) = Butterscotch
</CODE></PRE>
<H6>Example</H6>
<P>Consider the following form:</P>
<PRE><CODE>&lt;FORM ACTION = "/scripts/submit.asp" METHOD = "post"&gt;
&lt;P&gt;Your first name: &lt;INPUT NAME = "firstname" SIZE = 48&gt;
&lt;P&gt;What is your favorite ice cream flavor: &lt;SELECT NAME = "flavor"&gt;
&lt;OPTION&gt;Vanilla
&lt;OPTION&gt;Strawberry
&lt;OPTION&gt;Chocolate
&lt;OPTION&gt;Rocky Road&lt;/SELECT&gt;
&lt;P&gt;&lt;INPUT TYPE = SUBMIT&gt;
&lt;/FORM&gt;
</CODE></PRE>
<P>From that form, the following request body might be sent:</P>
<PRE><CODE>firstname=James&amp;flavor=Rocky+Road
</CODE></PRE>
<P>The following script can then be used: </P>
<PRE><CODE>Welcome, &lt;%= Request.Form("firstname") %&gt;.
Your favorite flavor is &lt;%= Request.Form("flavor") %&gt;.
</CODE></PRE>
<P>The following output is the result:</P>
<PRE><CODE>Welcome, James. Your favorite flavor is Rocky Road.
</CODE></PRE>
<P>If the following script is used:</P>
<PRE><CODE>The unparsed form data is: &lt;%= Request.Form %&gt;
</CODE></PRE>
<P>the output would be:</P>
<PRE><CODE>The unparsed form data is: firstname=James&amp;flavor=Rocky+Road
</CODE></PRE>
<P><span class=le><B>Note&nbsp;&nbsp;&nbsp;</B></span>If your form includes multiple objects with the same name (for example, HTML SELECT tags), the item in the form collection will be a comma-delimited list of all the selected values.</P>
<H6>Applies To</H6>
<P><A HREF="/iishelp/iis/htm/asp/vbob5ulw.htm"><B>Request</B> Object</A></P>
<H6>See Also</H6>
<P><A HREF="/iishelp/iis/htm/asp/vbob8q5h.htm"><B>ClientCertificate</B></A>, <A HREF="/iishelp/iis/htm/asp/vbob0z3o.htm"><B>Cookies</B></A>, <A HREF="/iishelp/iis/htm/asp/vbob53hj.htm"><B>QueryString</B></A>, <A HREF="/iishelp/iis/htm/asp/vbob5vsj.htm"><B>ServerVariables</B></A></P>
<hr class="iis" size="1">
<p align="center"><em><a href="../../../common/colegal.htm">&copy; 1997-2001 Microsoft Corporation. All rights reserved.</a></em></p>
</BODY>
</HTML>