FP98: How to Use Active Server Pages to Calculate Form Results (180824)



The information in this article applies to:

  • Microsoft FrontPage 98 for Windows

This article was previously published under Q180824

SUMMARY

Microsoft FrontPage includes a Save Results Form Handler that you can use to save information submitted from a form to a text file. You can also use Active Server Pages (ASP) to save submitted information to a file. This might be desirable if the FrontPage Server Extensions are not installed on the server or if calculations, such as computing sales tax, need to be performed on the submitted data.

MORE INFORMATION

Before you can use ASP, you must install the ASP engine on the Web server. The ASP engine can be found in the \60 Minute Intranet Kit\60 Minute Intranet Kit\Modules folder on the FrontPage 98 compact disc.

For more information about installing ASP, please see the following article in the Microsoft Knowledge Base:

174185 FP98: ASP Code Displayed in Browser

To use Active Server Pages to save the results of a form to a text file, follow these steps:

  1. On the Windows Start menu, point to Programs, and click Windows Explorer. In Windows Explorer, create a folder on the C: drive called "public" (without the quotation marks).
  2. Start FrontPage Explorer. Open or create a new FrontPage Web. To do this, point to New on the File menu, and then click FrontPage Web.
  3. Create a folder in FrontPage Explorer. To do this, follow these steps: a. On the View menu, click Folders. b. On the File menu, point to New, and click Folders. c. Name the folder "Scripts" (without the quotation marks).
  4. Right-click the Scripts folder and click Properties on the menu that appears.
  5. In the Properties dialog box, click "Allow scripts or programs to be run," and then click OK.
  6. On the Tools menu, click Show FrontPage Editor.
  7. Click the HTML tab at the bottom of the window and then enter the following Microsoft Visual Basic Scripting Edition (VBScript) code between the <body> and </body> tags. NOTE: The FileSystemObjects constants are required in order for this example to work.
    
    
          <H3> Thank you for submitting your information </H3>
          <%
          '-----------------------------------------------------
          ' FileSystemObject constants include file for VBScript
          '-----------------------------------------------------
    
          '---- iomode Values ----
          Const ForAppending = 8
          Const ForReading = 1
          Const ForWriting = 2
    
          '---- format Values ----
          Const TristateFalse = 0
          Const TristateMixed = -2
          Const TristateTrue = -1
          Const TristateUseDefault = -2
    
          ' If the file already exists, then an error will be generated.
          ' This line permits the program to continue executing on error.
          On error Resume next
          ' Create the scripting object.
          set objfso = createobject("scripting.FileSystemObject")
    
          ' Create the text file. If the file already exists, then an error
          ' will be generated.
          set myobject = objfso.createtextfile("c:\public\myfile.txt", false)
    
         ' Open the file for scripting.  If it does not exist, setting
          ' the third parameter (Create) to true will cause it to be created
          set myobject = objfso.opentextfile ("c:\public\myfile.txt",  forappending, true )
    
          'Calculate the total price.
          quantity = request.form("quantity")
          price = request.form("price")
          totalprice = quantity * price
    
          ' Assign the submitted form results to a variable.
          productdata = request.form("name") & "," & request.form("product") &
          "," & request.form("quantity") & "," & request.form("price") & "," &
          totalprice
    
          ' Write the form results to the file.
          myobject.writeline(productdata)
    
          ' Close the object.
          myobject.close
          %>
  8. Save the file and name it "Submit.asp" (without the quotation marks). Save the file in the Scripts folder that you created in Step 3.
  9. Create the form by following these steps: a. In FrontPage Editor, create a new page. To do this, click New on the File menu, click the Page tab, select Normal Page, and click OK. b. On this page, create a form with four one-line text boxes, and insert a Submit button. To insert the form field, point to Form Field on the Insert menu and then click One-Line Text Box. NOTE: The Submit button will automatically appear the first time you insert a form field. c. Name the four text-boxes "Name," "Product," "Price," and "Quantity"(without the quotation marks) respectively. To do this, right-click a text box and then click Form Field Properties on the menu that appears. The names must match the names referred to by the Request.form statements in Step 6.
  10. Set the form to execute the ASP file (Submit.asp), by following these steps: a. Right-click the form and then click Form Properties on the menu that appears. b. Click Send To Other. c. In the Send To Other list, click "Custom ISAPI, NSAPI, CGI, or ASP Script." d. Click Options. e. In the Action box in the "Options for Custom Form Handler" dialog box, type the following: Scripts/submit.asp
  11. Save the file in the root of the Web and name it "Default.htm" (without the quotation marks).

REFERENCES

For more information about VBScript constants, please see the following article in the Microsoft Knowledge Base:

163009 Values for Scripting Object Constants Defined


Modification Type:MajorLast Reviewed:12/1/2000
Keywords:kbhowto KB180824