Understanding How Forms Work

 < Day Day Up > 



Forms are created with HTML tags. The <form></form> pair surround other form object tags, such as <input>, <select>, and <submit>, to name a few. Form objects are used to collect, and sometimes to display, information. You give each form object a unique name when you use it in a form so that the combination of the form object's name and the information supplied by the user (value) results in a name-value pair.

Name-value pairs are useful. They can be delivered in an e-mail, stored as data for a field column (where name = field, value = column), or remembered as a scripted variable by the visitor's computer. The way name-value pairs are used depends upon the type of technology used to handle or process the form.

Form technologies

Dreamweaver contains easy-to-use tools for building forms, but a form by itself really has no power. A client or server technology is required to tap into the values of the form objects. The first step to using a form is to define its purpose, which you accomplish by choosing and using an appropriate technology.

Cross-Reference 

See Chapters 46 and 48, in which ASP and ColdFusion technologies power forms that collect, store, pass, and display data.

Mailto:

The simplest method of using form name-value pairs collected from a form is to e-mail them to an individual who then transfers the data to some type of paper or digital storage. All that's required is that you place the e-mail address in the form of mailto: in the action field of the form tag, as shown in Figure 38-1. This is generally not a secure method of transfer and most browsers inform you of this fact when you submit the form. This technology is appropriate for only the most casual of information, and data delivered this way isn't formatted for easy reading.

click to expand
Figure 38-1: Simple but insecure form. Place the mailto: e-mail address in the action field of the form tag.

Cross-Reference 

See Chapter 35 for more on creating mailto links.

Cookies

Some form of data is collected for use on the Web and stored using client-side scripting as a "cookie" on the visitor's computer hard drive. Client-side means that processing is done on the visitor's computer. Cookies are tiny bits of information that are stored for a set time period in a special location on the visitor's computer, and JavaScript is generally the power behind this type of form handling. A typical example of cookie usage would be to collect a visitor's name and preferences. The information is stored and then accessed via additional scripting during the current or subsequent site visits. The down side of cookies is that many users block them from being written to their computer by changing their browser preferences.

Server-side processing

A more powerful use of forms taps into server-side solutions. Server-side means that processing occurs on a remote (Web or application) server, not the visitor's computer. Scripts that live on the Web server parse (process) the data and do one or any combination of three things with it:

  • Send the information somewhere, usually by e-mail.

  • Reuse the information in dynamically generated content.

  • Store the information in a data source, either a database or text file on the Web server, for later use.

Server-side solutions are especially useful for retaining data. You cannot collect and store data from a form without some kind of server-side logic.

FormMail and other CGI scripts

Sometimes your form's purpose is to collect data and send it to someone. Most Web hosting companies have a standard CGI FormMail script that can e-mail form data to one or more recipients and even returns a thank you page after the form is submitted. This type of script uses Common Gateway Interface (CGI) protocol to control the way processed information is passed from the script or program back to the Web server and/or the user's browser. A CGI script enables a visitor to run or execute the script on the server. In the case of FormMail, an e-mail program on the Web server sends the collected and formatted data to the supplied recipient(s) address.

Most form data is collected via visible input fields or through menus, lists, radio buttons, or check boxes. Typically, a FormMail script includes one or more hidden fields that are contained in the source code but don't display in the browser. Visible form data values are most often supplied by the user; hidden field data is generally supplied by the Web page author.

To use a FormMail or any other CGI program, the script must be present on the Web server, generally in a cgi-bin folder, and specific permissions must be set to allow execution of the script. The path to a script is placed into the action field of the form tag. Generally, the type of path used is root-relative so that only Web pages on the same server may execute the script, which makes handling the URL easier for you as the developer. Some CGI scripts can also write data to a server, generally in the form of text files.

Web applications

Your form's purpose may be more complex than sending data via e-mail. The most powerful forms write and retrieve information to and from a data source that is stored on a remote server. In some cases, the information is reused as dynamic content in subsequent pages. This type of form requires handling by an application server — special software and drivers designed to interact and translate information to and from the database.

Typically, the form is placed into an HTML page that uses a special extension such as .asp, .cfm, .shtml, and so forth, to tell the Web server that the page must be processed before giving it to the visitor's browser. The scripting is processed as required, information is sent to the data source, and/or the HTML page is returned (minus the scripting) to the visitor. With Macromedia UltraDev now folded into Dreamweaver, you can select from several supported technologies to power your forms.

 ColdFusion MX   You can use Dreamweaver to add server-side logic to your forms. See Chapter 46 and the entire ColdFusion section in Part VI for more information about how to set up and script the form examples, including the forms set up in this chapter.

Working with forms

After you have defined your purpose and the information you need from a form, it's time to build the form in an HTML page. If you choose to use application logic such as .asp or .cfm, with your forms, you need to use the correct extension for your HTML page. However, you can build the form in a normal HTML page and change the extension later.



 < Day Day Up > 



Macromedia Studio MX Bible
Macromedia Studio MX Bible
ISBN: 0764525239
EAN: 2147483647
Year: 2003
Pages: 491

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