Part VI: Taking the Order

In this part of the project, you will take book orders over the network by simply recording orders in a text file. If you were creating a real-life Web site, you would want to provide a secure mechanism for taking orders, but this exercise gives you experience in using the text file components of Visual InterDev.

Step 1

If you don't already have the Bookstore project open in Visual InterDev, open it now. Add a new HTML file to your project by clicking the project title and choosing New from the File menu. In the New dialog box, insert a new ASP page, name the page ORDERFORM.ASP, and click the OK button.

Right-click ORDERFORM.ASP on the FileView tab, and choose Open With from the pop-up menu. In the Open With dialog box, open the file with Microsoft FrontPage Editor. You will use FrontPage to design an order form for the Web site.

Right-click the page, and choose Page Properties from the pop-up menu. Use the dialog box to change the background of the page to white.

Step 2

Build the order form by adding form elements through the Form Field items on the Insert menu. Use the following elements:


Control Type Control Name
One-Line TextBox txtName
One-Line TextBox txtAddress1
One-Line TextBox txtAddress2
One-Line TextBox txtCity
One-Line TextBox txtState
One-Line TextBox txtZip
One-Line TextBox txtCreditCard
Scrolling TextBox txtBookTitle
Push Button cmdSubmit
Push Button cmdReset

Insert each of the elements into ORDERFORM.ASP by choosing Form Field from the Insert menu. Change the name of each element by right-clicking the element and typing in the name from the table above. For the Scrolling TextBox, set Rows to 2 and Columns to 20. Change the button properties for cmdSubmit and cmdReset to Submit and Reset.

Step 3

Add an image to the top of the page by choosing Image from the Insert menu. In the From Location text box, type the following location:

/BOOKSTORE/IMAGES/ORDER.GIF

Right-click the form, and choose Form Properties from the pop-up menu. In the Form Properties dialog box, set Form Handler to Custom ISAPI, NSAPI, Or CGI Script. Click the Settings button, and enter ORDER.ASP in the Action text box. Click the OK button in both dialog boxes.

Save the page, and close FrontPage Editor.

Step 4

Open ORDERFORM.ASP in Visual InterDev. You need to add some server-side VBScript to automatically place the name of the ordered book in the form. Locate the <TEXTAREA> tag, which holds the book title, and insert the following code:

<P><TEXTAREA NAME="txtBookTitle" ROWS="2" COLS="20">     <%=Request.QueryString("Title")%>     </TEXTAREA> Book Title </P>

In Visual InterDev, choose New from the File menu. In the New dialog box, add a new ASP page, name the page ORDER.ASP, and click OK.

This page will acknowledge receipt of the order and print it in a text file. Use the text components of Visual InterDev to write instructions for the page. In the BODY section of ORDER.ASP, add the following code:

<H2><CENTER>Thanks for your order!</CENTER></H2> <% Dim objFile Dim objStream ` Open ORDER.TXT for writing Set objFile = Server.CreateObject("Scripting.FileSystemObject") Set objStream = objFile.OpenTextFile(Server.MapPath ("/Bookstore") + _                                      "\order.txt", 8, True) objStream.WriteLine Request.Form("txtName") objStream.WriteLine Request.Form("txtAddress1") objStream.WriteLine Request.Form("txtAddress2") objStream.WriteLine Request.Form("txtCity") objStream.WriteLine Request.Form("txtState") objStream.WriteLine Request.Form("txtZip") objStream.WriteLine Request.Form("txtCreditCard") objStream.WriteLine Request.Form("txtBookTitle") objStream.Close  Set objStream = Nothing Set objFile = Nothing %>

Step 5

Save your work, and test the order form by previewing ORDER.HTM in the Visual InterDev environment.

Step 6

Write your own code to add a hyperlink from the body of DEFAULT.HTM to ORDER.HTM. Add new commands to the Agent so that the Agent can take a user to the order form from the home page.

Save your work, and run the site. Test all the pieces.



Programming Active Server Pages
Programming Active Server Pages (Microsoft Programming Series)
ISBN: 1572317000
EAN: 2147483647
Year: 1996
Pages: 84

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