Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Perl CGl Programming: No experience required.
(Publisher: Sybex, Inc.)
Author(s): Erik Strom
ISBN: 0782121578
Publication Date: 11/01/97

Bookmark It

Search this book:
 
Previous Table of Contents Next


Submitting the Form

form1.html uses very few of HTML’s tricks, just a few text input types and the submit and reset buttons. Your purpose here is not to see how great-looking forms are put together, but to learn what happens when you or one of your visitors clicks that submit button.

There are two methods that can be used to send out the form’s data—the information that has been entered in its fields—and these are specified in the METHOD parameter to the HTML FORM command. You have used GET in this example; the other choice is POST. The difference between them is in how they send the data. As you will see, your choice in methods will be determined by the amount of data in the form; very generally, GET is used for small amounts and "POST" for large amounts or when you want to hide the information from the user.

You used GET in the example for two reasons: First, it’s short. Second, without even loading it on a Web site, you can get a visual idea of how the data are sent when you submit the form.

Create something to fool the browser. On Windows NT or Windows 95, if Perl is in your path (and it should be!), you can create a little file called perl.bat that has nothing in it but the word perl. A shell script on UNIX would accomplish the same thing.

Save it in the same directory in which you put form1.html, then crank up your Web browser of choice and open the file.


TIP:  Netscape Navigator has an option on its File menuto Open File in Browser. Microsoft Internet Explorer brings up an Open File dialog box when you choose the Open option in its File menu.

Fill out the form with anything that fits. Figure 5.4 illustrates some suggested bogus data.


Figure 5.4:  The form is filled out and ready to submit.

Now, submit the form by clicking the Send Information button.

Figure 5.5 illustrates what appears in Netscape Navigator’s Location field when you ship this form. The “CGI” program you specified in the form’s ACTION field doesn’t do anything, of course, but you can see what would be shipped to it.


Figure 5.5:  The URL sent by the form in Figure 5.4

This query string is set up by the browser as a URL. You don’t have to worry about how it’s done; any browser will do it automatically. However, you do have to interpret it in your CGI program, so you’d better know how it’s put together.

URLs and CGI

You have seen how an HTML form is built and the functions it uses to send information to the Web server. The form the information takes is important, because your Perl program has to be able to interpret it.

URLs, or Uniform Resource Locators, were developed as a way to specify resources on the Internet with a single line of printable ASCII text. Notice the emphasis on “printable”—this will become important to you as you learn to decode the special characters sent in a URL. In its simplest and most familiar form, a URL simply gives the domain name of a Web site, for example, www.rcich.com.

URLs aren’t limited to the World Wide Web. All of the major Internet protocols, such as FTP, Gopher, WAIS, and HTTP, can read and understand a URL. They are set up in a very specific way, containing:

  The protocol of the URL’s server (Gopher, WAIS, HTTP, etc.)
  The server’s domain name
  The server’s TCP/IP port number, which if omitted will default to the well-known port for the service—again, Gopher, WAIS, HTTP, etc.
  The location of the resource on the server

The URL that was constructed by your browser in submitting form1.html is set up in this fashion, with file// as the protocol, and the domain name, port, and resource location all addressed in the path to perl.bat. Figure 5.6 illustrates a full URL pointing over the Internet to the same location.


Figure 5.6:  The anatomy of a URL


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.