Chapter 4. Generating and Processing Forms

only for RuBoard - do not distribute or recompile

Chapter 4. Generating and Processing Forms

graphics/chic01.gif

In Chapter 2, Getting Connected Putting Your Database on the Web, we constructed a simple form-based application (the To-Do list manager) where we discussed topics related to form generation and processing, as we needed them. This chapter takes a more systematic approach. It lays out the structure of forms, describes the various kinds of elements you can use within forms, and discusses general techniques for extracting the contents of forms after they ve been submitted by users. In Chapter 5, Writing Form-Based Applications, we ll use the material presented here to build several different kinds of applications.

This chapter is the most MySQL-less of the book; nevertheless, everything discussed here is intended for the sole purpose of helping you use MySQL more effectively. Forms have many uses in a database context:

  • The data-entry capability afforded by forms enables you to collect commentary. Basic versions of this type of application just solicit information, such as a bare-bones guestbook that lets people tell you they visited your site. More elaborate versions involve taking some action based on the information submitted. An application that provides a form for customer complaints generates database records that must each be given attention for resolution of the issues raised. Or you might gather information as a means of constructing a searchable database for other people to use. If you have an application that collects and stores restaurant reviews, for example, you can provide a search interface so that visitors can look for information about a given restaurant to see how customers rate it.

  • Forms provide a natural interface for registration applications. You can use them to register conference attendees, to allow people to apply for accounts on an online auction site, to submit loan or credit card requests, and so forth. All of these generate records that you can store in your database.

  • Sign up for more information forms enable people to submit an address that you store and use later to send news or notifications when information on a topic of interest becomes available. This includes all kinds of things, such as mailing lists, daily weather reports, sports news, real-estate listings, and political campaign updates.

  • You can provide record-editing capabilities allowing table contents to be modified. Suppose you have an organization that maintains membership records. A form-based interface can be used to enable members to update their personal information: Your application would retrieve the appropriate membership record from the database and use its contents to initialize an editing form so that the member can modify the information.

  • Forms make it easy to implement polling and voting applications where you ask users to choose from a set of alternatives. Many such applications also offer access to the most recent up-to-the-minute results. The database enables you to store vote tallies and retrieve them to display current results.

  • Questionnaires and surveys map well onto forms, which provide a structured environment for presenting lists of questions and capturing responses. In some ways, a questionnaire is just a generalization of a poll from a single question to multiple questions. However, questionnaires often contain items that allow free text entry rather than just presenting a fixed set of alternatives.

  • Online ordering scenarios involve searching and selecting, two activities that typically are form based.

  • Forms enable users to specify actions that you perform on their behalf. For an auction site, you can let people submit profiles for items they re interested in, and then notify them when such items come up to bid. If you re out of stock on an item that a customer wants to buy, offer to let the customer know when the item becomes available and provide a form to collect an address or telephone number by which to contact the customer. You can collect specifications of stock market conditions that should generate email alerts ( the price of Acme Birdseed, Inc. has dropped below $14 a share ). An application that enables users to construct greeting cards generates email to card recipients, and later enables those recipients to retrieve cards that have been designed for them.

  • Search engines typically operate using a form-based front end that enables users to enter search parameters to describe what they want to see so that you can run searches for them.

You can probably come up with many other examples. Just think of all the paper forms you deal with in daily life, and consider how they might be handled via electronic submission and processing.

The preceding examples involve collecting information from the user and either storing it in the database or using it to construct a query to search for information already in the database. They illustrate the potential for treating your Web site as a front end that enables you to use your database more effectively. But information flows the other way, too. You can use your database to help you create your Web site. For example, you can take information from the database to automate certain aspects of form construction. If you associate a set of radio buttons in a form with the possible values of an ENUM column in a table, you can generate the button set automatically by reading the column definition directly from the table structure to see what the legal values are. You don t need to hardwire the possible choices into your script. You also can use table information to help automate form-input validation. (A simple example: If a form field corresponds to a table column that has an integer type, you know that values entered into the field must contain numeric values.) You can use this kind of information to reduce the amount of form-related programming you do. You may even decide to use tables to store entire form descriptions. If you do this, you can create forms completely automatically, an approach that also increases the likelihood that you can perform automated validation of responses without special-purpose programming. We ll take a look at some of these techniques in Chapter 6, Automating the Form-Handling Process.

only for RuBoard - do not distribute or recompile


MySQL and Perl for the Web
MySQL and Perl for the Web
ISBN: 0735710546
EAN: 2147483647
Year: 2005
Pages: 77
Authors: Paul DuBois

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