Microsoft KB Archive/281570

= How To Use ASP Request and Session Collections to Link HTML Forms =

Article ID: 281570

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft Internet Information Services 5.0

-



This article was previously published under Q281570



SUMMARY
This article describes how to use the Request and Session collections in Active Server Pages (ASP) to link the HTML forms on multiple Web pages.



MORE INFORMATION
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this code &quot;as is&quot; without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. To create the ASP sample, follow these steps:  In Windows Explorer, open the root folder of your Web site.  In Notepad, save each of the following pages in the root folder:

Page1.asp Page 1  NAME    Page2.asp Page 2  ADDRESS    Page3.asp Page 3  PHONE <input type=&quot;text&quot; name=&quot;PHONE&quot; size=&quot;20&quot;> <input type=&quot;submit&quot; value=&quot;Submit&quot;> <input type=&quot;reset&quot; value=&quot;Reset&quot;> Page4.asp <% ' Declare variables for later use. Dim strBody Dim objMail

' The following constants are used with the CDONTS.NewMail object: ' BodyFormat Property ' The Body property is to include HTML. Const CdoBodyFormatHTML = 0 ' The Body property is to be plain text (default). Const CdoBodyFormatText = 1 ' MailFormat Property ' The NewMail object is to be in MIME format. Const CdoMailFormatMime = 0 ' The NewMail object is to be in plain text (default). Const CdoMailFormatText = 1 ' Importance Property ' Low importance Const CdoLow   = 0 ' Normal importance (default) Const CdoNormal = 1 ' High importance Const CdoHigh  = 2 %> Page 4 <% strBody = &quot;  &quot; & vbCrLf

' Loop through the session collection. For Each objFIELD in Session.Contents ' Build a Web page from the collection values. strBody = strBody & &quot; &quot; & objFIELD & &quot; = &quot; strBody = strBody & Session(objFIELD) & &quot; &quot; & vbCrLf Next

strBody = strBody & &quot; &quot; & vbCrLf

' Create a mail object. Set objMail = CreateObject(&quot;CDONTS.NewMail&quot;) ' Set email addresses. objMail.From = &quot;someone@microsoft.com&quot; objMail.To = &quot;someone@microsoft.com&quot; ' Add the subject. objMail.Subject = &quot;Form Results&quot; ' Set the mail format. objMail.BodyFormat = CdoBodyFormatHTML objMail.MailFormat = CdoMailFormatMime ' Add the Web page. objMail.Body = strBody ' Send the email. objMail.Send Set objMail = Nothing ' Erase the session collection. Session.Abandon %> Your results have been mailed! Session.inc <% ' Loop through the submitted form fields. For Each objFIELD in Request.Form ' Save each value in a session variable. Session(objFIELD) = Request.Form(objFIELD) Next %>                   </li> When Page1.asp is browsed through HTTP, the values that are submitted on the form are passed to Page2.asp.</li> Page2.asp uses the server-side include file, Session.inc, to loop through any fields from the form on Page1.asp through the Request collection and saves the values to the Session collection.</li> This behavior is repeated for Page3.asp and Page4.asp, but Page4.asp contains additional ASP code that loops through the Session collection and builds and HTML page that will be sent by e-mail message.</li></ol>