DOCUMENT:Q281570 21-DEC-2000 [iis] TITLE :HOWTO: Use ASP Request and Session Collections to Link Forms PRODUCT :Internet Information Server PROD/VER::5.0 OPER/SYS: KEYWORDS:kbdta kbDSupport kbiis500 ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Internet Information Services version 5.0 ------------------------------------------------------------------------------- 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 "as is" 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: 1. In Windows Explorer, open the root folder of your Web site. 2. 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

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 = "" & vbCrLf ' Loop through the session collection. For Each objFIELD in Session.Contents ' Build a Web page from the collection values. strBody = strBody & "

" & objFIELD & " = " strBody = strBody & Session(objFIELD) & "

" & vbCrLf Next strBody = strBody & "" & vbCrLf ' Create a mail object. Set objMail = CreateObject("CDONTS.NewMail") ' Set email addresses. objMail.From = "someone@microsoft.com" objMail.To = "someone@microsoft.com" ' Add the subject. objMail.Subject = "Form Results" ' 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 %> 3. When Page1.asp is browsed through HTTP, the values that are submitted on the form are passed to Page2.asp. 4. 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. 5. 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. References ---------- For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base: Q218607 How to Create a File Defining the Constants for Use w/ CDONTS Q186204 HOWTO: Use CDONTS to Collect and Mail Information From a User Additional query words: iis ====================================================================== Keywords : kbdta kbDSupport kbiis500 Technology : kbiisSearch kbiis500 Version : :5.0 Issue type : kbhowto ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 2000.