Sun Chili!Soft ASP Sun Chili!Soft
ASP Sun Microsystems


ASP Request Object Form Collection

The Form collection retrieves the values of form elements posted to the HTTP request body by a form using the POST method.

Syntax: ASP Request Object Form Collection


Parameters: ASP Request Object Form Collection


Specifies the name of the form element from which the collection is to retrieve values.


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 Count.

Remarks: ASP Request Object Form Collection

The Form collection is indexed by the names of the parameters in the request body. The value of Request.Form(parameter) is an array of all of the values of parameter that occur in the request body. You can determine the number of values of a parameter by calling Request.Form(parameter).Count. If a parameter does not have multiple values associated with it, the count is 1. If the parameter is not bound, the count is 0.

To reference a single value of a form element that has multiple values, you must specify a value for the index. The index parameter may be any number between 1 and Request.Form(parameter).Count. If you reference one of multiple form parameters without specifying a value for index, the data is returned as a comma-delimited string.

When you use parameters with Request.Form, 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 Request.Form without any parameters.

Examples: ASP Request Object Form Collection

In this example an iterator is used to loop through all the data values in a form request. Assume that a user fills out a form by specifying two values (Chocolate and Butterscotch) for the FavoriteFlavor parameter. The following script will retrieve these values:

For Each item In Request.Form("FavoriteFlavor")

Response.Write item & "<BR>"


This displays the following:



The same output can be generated with a For...Next loop, as shown in the following script:

For I = 1 To Request.Form("FavoriteFlavor").Count

Response.Write Request.Form("FavoriteFlavor")(I) & "<BR>"


This iterator can display the parameter name, as shown in the following script.

<% For Each x In Request.Form %>

Request.Form( <%= x %> ) = <%= Request.Form(x) %> <BR>

<% Next %>

This displays the following:

FavoriteFlavor = Chocolate

FavoriteFlavor = Butterscotch

The next example uses the following form to solicit information from a user:

<FORM ACTION = "/scripts/submit.asp" METHOD = "post">

<P>Your first name: <INPUT NAME = "firstname" SIZE = 48>

<P>What is your favorite ice cream flavor: <SELECT NAME = "flavor">







From that form, the following request body might be sent to the client:


The following script can then be used:

Welcome, <%= Request.Form("firstname") %>.

Your favorite flavor is <%= Request.Form("flavor") %>.

The unparsed form data is: <%= Request.Form %>

This displays the following:

"Welcome, James. Your favorite flavor is Rocky Road."

The unparsed form data is: firstname=James&flavor=Rocky+Road

Copyright 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.