The Request Object

Using the Form Collection

The Form collection of the Request object extracts information from the body of an HTTP request message.
Note

If the form method is GET, the QueryString collection will contain all information passed in the form.


The Form collection contains the values of each standard HTML control that has a NAME attribute. When a user submits a form with the Post method, you can read the values of the controls by using the Form collection.

Example

When a user completes and submits a form with this HTML:
 <FORM ACTION="submit.asp" METHOD=POST> Name: <INPUT TYPE=TEXT NAME="name"><P> Favorite Color: <SELECT MULTIPLE NAME="color"> <OPTION>Red <OPTION>Green <OPTION>Blue </SELECT><P> <INPUT TYPE=SUBMIT NAME="cmdSubmit" VALUE="Submit"> </FORM> 

You can read the submitted information by using the following script in the submit.asp file:

 Request.Form("name") Request.Form("color") 

You also can loop through all of the values on a form to extract information passed by the user.

Example

This example loops through all of the standard HTML controls in an HTTP request:
 <% For Each Item in Request.Form 'Display Item Next %> 

If more than one value is submitted for a control on a form, such as a multiselect list box, use the index of the Form collection variable to access the individual values.

Example

This example shows how to access the first and second color value selected in the color list box:
 Request.Form("color")(0) Request.Form("color")(1) 

Lesson Summary

The Request object retrieves values from an HTTP request. The Request object provides access to any information that is passed to the Web server; however, it contains five collections that extract different types of data. The QueryString collection extracts information from the header of an HTTP request. The Form collection retrieves data from the body of the HTTP request. The Cookies collection retrieves the values of cookies sent in the HTTP request. The ClientCertificate collection retrieves the values of the certification fields of the request, and the ServerVariables collection gets the values of predetermined Web server environment variables.


Microsoft Windows Architecture Training
Microsoft Windows Architecture for Developers Training Kit
ISBN: B00007FY9D
EAN: N/A
Year: 1998
Pages: 324

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net