Chapter Three
It's easy to get started with PolyForm, and this chapter will show you how. You will learn to use the PolyForm Control Panel to create a series of instructions on how to handle information someone types into a form and submits.
These instructions are called a script. We call the information typed into the form the form contents. Since the form, the script, and sometimes other files all work together, we often refer to the whole set as an application.
The script tells the PolyForm CGI program which form to use, if and how you want to save the form contents, what you want to send back to the browser, and what kind of (if any) email you want PolyForm to send regarding the form contents.
The fastest way to create a new form and script is to use the PolyForm Script Wizard, which you start from the PolyForm Control Panel. You can create a form and its script, and try them out in about a minute! It might take a little longer the first time, but not much longer. You can later fine-tune the form by editing the HTML form file; you can change the script as well, using the PolyForm Control Panel.
This chapter will:
After reading through this chapter to create your first applications, you will be ready to add forms to your web.
The method for reaching the PolyForm Control Panel icon that is used to run the PolyForm Control Panel, depends on the operating system you are using.
If your operating system is Windows 95 or Windows NT 4.0, PolyForm's Setup program creates a folder on your program menu called PolyForm 1.0. This folder contains three icons:
If your operating system is Windows NT 3.51, you selected a Program Group for your PolyForm icons during installation. The Program Group contains the icons listed above, plus the PolyForm Uninstall icon.
Select the PolyForm Control Panel icon and press Enter to start the PolyForm Control Panel. (See Figure 3-1.)
The first time you run PolyForm Control Panel, you should indicate which Web browser you use. On the Options menu choose Settings. Choose the Applications tab. Use the browse button beside the Browser field to indicate the path and filename of your Web browser. You may also use the browse button beside the Text Editor field and the HTML Editor field to indicate the path and filename of the editors you want to use. For more information see "Changing the PolyForm Control Panel Settings," at the end of this chapter.
The section of this chapter called "Using the PolyForm Control Panel to Create a Script," gives you step-by-step instructions to create a script as quickly as possible. If you feel like you are ready, skip ahead to that section now. Otherwise keep reading and you'll get a quick tour of the PolyForm Control Panel's menus and tabs.
When you first open the PolyForm Control Panel (either through the Start menu in Windows 95 or by double clicking the icon in a Windows NT Program Group) it is ready for you to get to work. (See Figure 3-1.)
Figure 3-1 PolyForm Control Panel
Notice the menus, the toolbar, and a series of tabs that make up the PolyForm Control Panel. A brief synopsis of the menus and toolbar icons is presented in Table 3-1.
Table 3-1 Synopsis of menus and toolbars icons
The tab that is displayed when you open the PolyForm Control Panel is the Form tab. You may enter the name of an existing HTML form, or create a new form. The buttons to the right of the Form Filename field are the Browse button and the Edit button. Use the Browse button to create a new file, and use the Edit button to edit the HTML source. The "Allow only this Form to run this Script" checkbox is a security feature, discussed fully in Chapter 4, PolyForm Tools.
On the Save to File tab, shown in Figure 3-2, you select an option for saving the form contents to the server's disk drive. You may save the form contents in a text file, in a data file, in one of two kinds of templates, or not at all. Each method of saving the form contents is discussed in detail in Chapter 4, including step-by-step instructions.
Figure 3-2 Save to File tab
The Send to Browser tab, shown in Figure 3-3, gives you three options for the type of document to send to the form user's browser after a form is submitted: the URL of an existing document, a document based on a template that is an HTML document into which PolyForm has inserted information from the form, and a document that simply echoes the information entered into the form.
The Send to Browser tab also allows you to enter a Window Target for sending results to a specific window or frame in browsers that support frames. See Chapter 4 for details on these features.
Figure 3-3 Send to Browser tab
On the Email Options tab, shown in Figure 3-4, you can tell PolyForm to send two types of email. One type is a simple list of the form contents sent to an email address you enter on this tab; it may also be a list of email addresses in a file. The other type of email message is based on a template, and may be sent to an email address entered on the form. Again, see Chapter 4 for complete descriptions of these features and step-by-step instructions on how to use them.
Figure 3-4 Email Options tab
PolyForm's Script Wizard is the easiest way to create a script. You choose which of the included forms to use, select a few options, and-voila!-you are ready to go.
The wizard displays the entire list of forms to choose from, but here are a few examples:
The rest of this section walks you through the steps to create a feedback form and script with the wizard. As you work through the following step-by-step instructions you will start by creating a feedback form document. The script you create will do the following: When someone types information in the form, then clicks the submit button, the script sends a document back to the browser that shows the user what has been typed. PolyForm also sends the form contents to you in an email message.
Here are the main steps of the process:
The first step is to start the Script Wizard. To start the PolyForm Script Wizard, follow these steps:
Figure 3-5 PolyForm Script Wizard
On the Form screen choose the form with which you want to work. For this example, select the Feedback Form.
Figure 3-6 PolyForm Script Wizard Form screen
The wizard gives you three options for saving the form contents. You may choose to save as a simple text file, as a data file, or not to save at all. For this example, you will email the form contents to your email address instead of saving to disk.
Figure 3-7 PolyForm Script Wizard Save Form Contents screen
Whenever someone submits a form to PolyForm, PolyForm sends an HTML document back. This return document is called the response to the browser. The wizard gives you two choices: a very simple document that echoes the form contents, or the URL of a file that you create separately.
It is very easy to choose the first option, even if you plan later to create a specific HTML document to send to the user's browser. For this example, select the first option: to echo the form contents.
Figure 3-8 PolyForm Script Wizard Response to Browser screen
When using the wizard, you may decide to send the form contents to an email address you enter. Sometimes you might want to do this in addition to or instead of saving the form contents in a file.
The script you are building will send the form contents to you by email. On this screen you also enter the From and Subject of the email message. (See Figure 3-9.)
Figure 3-9 PolyForm Script Wizard Emailing screen
The script name must contain only letters, numbers, and underscores; no spaces or other symbols are permitted. Also, it must be 32 characters or fewer in length.
We recommend you use names that describe the purpose of the form and script. In this case, you might use Feedback_Form. You may also want to establish a standard approach to naming scripts. This example begins each word with an uppercase character, and connects words with an underscore. If you always follow the same standard, it will be easier to avoid mistakes.
Figure 3-10 PolyForm Script Wizard Script Name screen
You are now almost done creating the script. If you want to review your selections, you may choose Back one or more times to view previous screens.
The wizard closes, and the new script is open in the PolyForm Control Panel.
You run your script by opening the form in a browser, entering information on the form, and pressing the Submit button. PolyForm then executes the script and responds accordingly. If the form and response are what you expected, your wizard experience was a success. Note that you can always enhance the form or the script from the PolyForm Control Panel.
You can also run PolyForm scripts simply by choosing Run on the PolyForm Control Panel Options menu. The Run command uses your Web browser and server to load the form associated with the open script. You may then enter information and submit the form to run the script. You may, however, need to bring the browser window to the front, as follows.
Figure 3-11 Feedback Form
Figure 3-12 Response to browser
Congratulations, you have just created and run your first PolyForm script!
You will also receive the form contents as an email message if you have an SMTP mail server installed and configured. You may further customize the script or form through the PolyForm Control Panel. The following section shows you how to use the PolyForm Control Panel to create a script.
This example uses the PolyForm Control Panel to create a simple HTML comment form and its script. The end result will be very close to what you created in the previous example using the Script Wizard.
The main steps in this process are:
When you start the PolyForm Control Panel, it is ready for you to enter a new script. But if you have been working with other scripts you will need to do the following:
If changes to the current script haven't been saved, PolyForm displays the Save Changes? dialog. Choose Yes to save the previous script.
If the current script has never been saved, and therefore has no script name, PolyForm Control Panel displays the Save As dialog. Enter a script name and choose OK to save the script.
You will now have a new script to work with in the PolyForm Control Panel. (See Figure 3-13.)
Figure 3-13 Control Panel with new script
Typically, creating the HTML form is the first thing to do when building a script. The following example shows you one way to create a form through the PolyForm Control Panel.
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.0//EN" "html.dtd"> <HTML> <HEAD> <TITLE>Comment Form</TITLE> </HEAD> <BODY> <H1>We'd like to hear from you!</H1> <HR> <FORM METHOD="POST" action="/cgi-win/polyform.exe/Comment_Form"> <p>Name: <input type="text" name="name"><br> Email: <input type="text" name="email"> <p>Comment:<br> <textarea name="comment" cols="40" rows="5"> </textarea> <p>To submit the form, press this button: <INPUT TYPE="submit" VALUE="Submit Comments"> <P> To clear the form, press this button: <INPUT TYPE="reset" VALUE="Clear Form"> </FORM> <p>Thanks! <HR> </BODY> </HTML>
Note that the action attribute of the form tag tells your server to name the script and to run PolyForm.
<FORM METHOD="POST" action="/cgi-win/polyform.exe/Comment_Form">
In this case the script name is Comment_Form. Script names must be 32 characters long or fewer; you may use letters, numbers, and the underscore, but you may not use spaces or other symbols. When you save the script, you must type the script name exactly as you entered it in the action attribute of the form.
We suggest that you use names that make it obvious what the form is about. We also suggest that you consider using consistent standards for script names. For example, always capitalize words in script names, and type an underscore between words. Comment_Form fits this standard.
Figure 3-14 Outline of HTML document in editor
The Send to Browser tab gives you several options for what PolyForm should send to the browser when the form is submitted. You select one of the following: the URL of a document that you create and save on the server, a template file that creates an HTML document on the fly, or a simple confirmation of the data received from the form.
You may also enter a Window Target to send the results to a named frame or browser window for browsers that support frames. See Chapter 4 for more information about this feature.
In this example you will send a confirmation of data received.
Figure 3-15 Send to Browser tab
Use the Email Options tab to send email both to an address you enter, and to an address submitted by the form. In this example, just send email to yourself.
If you don't have an SMTP mail server, PolyForm won't be able to send email. (See Chapter 2, Installing PolyForm, for details.)
Figure 3-16 Email Options tab
You have now created each element of a PolyForm script. You are ready to save the new script.
In the Script Wizard example, you tested the script by using PolyForm's Run command. This time, you'll test the script by giving the URL of the script directly to your browser.
Figure 3-17 Comment_Form form document
Figure 3-18 Comment_Form response to the browser
You have now created, saved, and run a PolyForm script through the PolyForm Control Panel. As you've seen, there are more options than the Script Wizard. You may find it desirable to create a script with the wizard initially and then modify it with the PolyForm Control Panel.
Just to add one more step to this process, try the following procedure that introduces you to the report you can generate on your scripts.
The Script Report answers questions you may have about your script. The report contains all the information you supplied while creating your script, through the Script Wizard or the PolyForm Control Panel, the path and filename of the form file, and the contents of the form file.
To view the script report for the open script, choose Report on the PolyForm Control Panel Options menu. PolyForm displays a report in your text editor. A complete report listing is shown in Example 3-1. You can save the report to another filename or print the report. We recommend that you keep copies of script reports for reference.
Example 3-1 Report Listing of Comment_Form Script
Report of Comment_Form script. 3/11/96 9:58:01 PM -----Form Attributes----- Form Title: Comments Form file name: F:\win32app\internet\WEBSITE\CGI-WIN\PFTOOLS\FORMS\Comment_Form.html Form Tag Syntax: <FORM METHOD="POST" ACTION="http://localhost/cgi-win/polyform.exe/Comment_Form"> URL of this Form: http://localhost/cgi-win/polyform.exe/Comment_Form Form: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.0//EN" "html.dtd"> <HTML> <HEAD> <TITLE>Comments</TITLE> </HEAD> <BODY> <H1>We'd like to hear from you!</H1> <HR> <FORM METHOD="POST" action="/cgi-win/polyform.exe/Comment_Form"> <p>Name: <input type="text" name="name"><br> Email: <input type="text" name="email"> <p>Comment:<br> <textarea name="comment" cols="40" rows="5"> </textarea> <P> To submit the form, press this button: <INPUT TYPE="submit" VALUE="Submit Comments"> <P> To clear the form, press this button: <INPUT TYPE="reset" VALUE="Clear Form"> </FORM> <p>Thanks! <HR> </BODY> </HTML> -----Saved to File Attributes----- No information is saved by this script -----Send to Browser attributes----- The browser will be sent an acknowledgement of the submission containing the submitted data and based on a default template. -----Email Options----- Email containing the submitted contents of the form and transaction specific information will be sent to: jrb@myserver.com (If a filename, file contains multiple email addresses) Subject of Email: Email sent from: -----End of report-----
There may be a situation at some point that requires you to modify the information (mailserver, CGI URL, etc.) you provided to the Install Wizard when installing PolyForm. Before moving on to Chapter 4, PolyForm Tools, and each specific PolyForm tool, let's explore the Settings option on the Options menu.
To update the installation information, on the PolyForm Control Panel Options menu, choose Settings. (See Figure 3-19.)
Figure 3-19 Settings window displaying the Server Properties tab
The Server Properties tab allows you to modify the following:
After installing PolyForm, you may use the Applications tab of the Settings form to choose editors for HTML and text files. PolyForm uses the Windows Notepad unless you change this setting. (See Figure 3-20.) You may also enter the path and filename of your Web browser. Once you specify your browser here, PolyForm will load the active script's form into the browser whenever you choose Run on the Options menu in the PolyForm Control Panel.
Figure 3-20 Settings window displaying the Applications Properties tab