• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Day 3. Advanced HTML and Site Tools > Forms: A Brief Introduction

Forms: A Brief Introduction

An HTML component that you haven't seen yet is the form. Forms are used to create the interactive elements of Web sites. As such, it isn't something you'll really get a chance to use until you've reached the dynamic portions of Dreamweaver MX. If you need to create forms that connect to existing dynamic applications, you'll have to learn the tools, so let's do that now.

There really isn't a good way to demonstrate the use of form elements until they come into play later in the text, so this will just serve as a reference until later.

Here is a summary of Insert panel form objects, and what they're used for:

Form— The <form> tag set contains the other elements in the form and determines how they will be transmitted to an application for processing. Just as a <table> object holds rows and cells, the <form> holds input fields, buttons, and so on.

Text Field— Text fields are used to collect information from the users. Although text fields are single-line elements, Dreamweaver MX abstracts the text field to a point where it can instantly be converted to and from a multiline field (actually a <textarea>).

Hidden FieldHidden fields are used to carry data along with the form that you might not really want the user to see. Check out Day 6, “Introduction to Dynamic Web Applications and Database Design,” for more information on variable passing. Hidden fields should never be used to pass sensitive information. Users can always create a local copy of a form with hidden fields and manually edit the fields to contain whatever data they want. A bank, for example, wouldn't want to pass a user's current balance around through a hidden field. The users could potentially edit the value and drastically increase their net worth.

Text Area— Text areas, like text fields, are used to collect information from the users. Text areas, however are multiline text fields and can collect several lines of information. Dreamweaver MX can convert text areas to text fields and vice versa.

Check Box— The check box is used to create a group of items that can be turned off or on. This is usually used on a form to select multiple attributes that apply to something (implying an AND state). The most common misuse of the check box is applying it to OR states, such as “Click yes OR no.”

Radio Button— Similar to the check box, the radio button also enables users to choose among several attributes on a form. Unlike the check box, however, the radio should be used when an OR state is implied. If two radio buttons share the same name, they are mutually exclusive of one another. (Both cannot be selected at the same time.) Radio buttons are sometimes used in the place of check boxes. If each radio button is named differently, this almost works. When a radio button is set, it cannot be unselected unless a Reset button is supplied for the form.

Radio GroupBecause radio buttons are usually added in groups, the Radio Group tool automates the process. This is used to create a collect of like-named radio buttons and their labels.

List/Menu— The list/menu is a rather bizarre construct because it behaves very differently between its two forms. In one configuration, it is simply a pop-up menu that can be used to choose one option among several choices (for example, choose your state from the list). In its other incarnation, it displays as a rectangular scrolling list in which multiple items can be highlighted. In my opinion, although they take more room, check boxes are better suited to providing the “pick all that apply” functionality than lists are.

Jump Menu— The jump menu is not a form element, but is a JavaScript construct that you can use on any page, regardless of whether it is part of a server-processed form. Creating a jump menu in your document creates a simple pop-up menu that visitors can use to quickly jump to different parts of your Web site.

Image Field— Image fields are typically used as graphical form submit buttons, yet they also transmit back information to the server in the form of the X and Y coordinates where the click took place—just like an image map.

File FieldThe file field is finally starting to be useful now that all modern browsers support it. If you've seen one of the “Upload your files to 20MB of free remote storage” Web sites, you've probably seen the file field in use. The file field enables a Web page to submit an entire file to a server for processing. Some of the more interesting uses of this feature have been on Web pages that allow retailers to customize their merchandise by uploading a logo that is then mapped to their product catalog.

Button— Button elements are most frequently used to submit the contents of a form, or reset them to their default values.

Label/Fieldset— The final two buttons in the form category of the Insert panel—label and fieldset—simply insert the <label> and <fieldset> tags into the document. They do not add anything to the design window.

As you work with form elements, you'll start to understand the common elements between them. Most form elements, for example, submit information, have a default value, and a name.

Text Fields

For example, let's take a look at the most common element you'll see—text fields. Add in a text field by clicking the Text Field icon in the Tool panel or by choosing Text Field from the Form Object submenu under Insert. A single field should be inserted into the document. Select the field in the design view and open the Properties panel, shown in Figure 3.22.

Figure 3.22. Form objects have properties, just like everything else.

Here you can change the attributes of the text field that is being used in the document. The three variations of fields available from the one Text Field tool are as follows:

Single line— Inputs a single line of text at a time. Although you can use this to input long sentences and even paragraphs, it's mostly useful for gathering one or two words from the users. This is the default text field type.

Multi line— Lets the users type multiple lines of data in a more free-form style. This field type does not allow styles as in a traditional word processor, but does give the same cursor control that users are accustomed to. Although accessed using the same Text Field tool, this form element is actually quite different from the other two options.

PasswordThe password field is just what it sounds like, a field for entering passwords. This field type is identical to the single line field, but it replaces the user input with symbols so that it can't be read. In all honesty, there is very little protection offered by using this field on a page. It does not secure a site and only offers a very basic visual form of protection.

Besides setting a field type, you also need to set a name for each field. This name will be used by the Dreamweaver server behaviors to receive and process incoming data.

A few other fields can be set in order to restrict the user's input or change the way the field is displayed onscreen. They are as follows:

Char WidthThe character width attribute determines the number of characters that can be entered into the field and displayed onscreen at a time. This does not affect the number of characters that the field can hold; only the number that can be seen.

Max Chars (Single line and Password only)— The maximum number of characters a field can hold. Use this value to set an upper limit on the typing that a user can perform. This is useful for keeping data within the defined size limits of the fields.

Num Lines (Multi line option only)— For multi-line displays, this attribute replaces the Max Chars option. The Num Lines determines the number of rows of text that will be visible to the users when they enter information. There is no way to set the maximum number of characters in a multi-line field, other than checking its size with JavaScript.

Init Val— The initial value that the field will contain. This value will show up in the form when it is first displayed. This value can be edited by the person viewing the form.


Be careful when using initial values. Users have a tendency to skip over already filled-in fields. You might end up with bad data unless you force them to choose a value.

Wrap (Multi line option only)— The Wrap attribute controls how text is wrapped when the end of the line is reached in a multi-line form element. The Off setting will scroll the text area horizontally when the user reaches the edge of the text area. Pressing Return is the only way to start a new line. Virtual will automatically place the cursor on the next line when it reaches the edge of the text area but doesn't add an EOL (End of Line) character to the text. Physical behaves the same way as a Virtual wrap, but it does insert an EOL at the end of each line.

Submit Buttons

Another common form element is the button. Buttons are usually used to trigger the processing of form information. Clicking the button object in the Insert panel will add a basic Submit button to the form at your present cursor position.

The properties of a simple Submit button are shown in Figure 3.23.

Figure 3.23. You can name your button from the Properties panel.

If you're just using the button to submit a form, most likely all you need to set is the label. The button label is the text that is actually drawn inside the button graphic on the page. Don't confuse this with the button name, which provides a form field name for the button object.


What good is a field name for a button? Actually, buttons are just as valid an input device as any other field on a form. For example, assume that you have a form collecting data on your inventory of video tapes. Rather than having a radio button or text field that needs to be set each time for the rating (G, PG, PG-13, R, or NC-17), you could set the value as part of the submit process. You would just create five submit buttons sharing the common name “rating.” Each would submit a different value for the movie's rating when it is clicked. Don't discount the usefulness of the button as an input device.

There are two other actions that a button can take on. The action you've probably seen before on other pages is the reset action. A button defined as a reset button and added to a form will automatically change all field values to their defaults when it is clicked. This provides a convenient way for a user to start over without having to manually clear out data from the fields in the form.


Be careful when labeling and placing your Submit and Reset buttons on the page. If a user spends 15 minutes filling out a form on a page, only to click the Reset button because it is featured more prominently than the Submit button, he or she is likely to give up.


The reset action resets the form to its initial empty state. If you used initial values for your fields, however, those values are restored as well.

The other type of button action, None, is no action at all. This is generally used in conjunction with JavaScript to provide client-side behaviors.

Image Buttons

If you want to be fancy with your presentation, there is another type of button you can use to submit data: an image button. This button is a bit strange in that it doesn't submit data to the server in exactly the same format as the standard HTML Submit button. To add an image button to your document, click the Image Field item in the Forms panel. As with any image, you'll be prompted for the location of the image file. This is a pure HTML construct and doesn't use any JavaScript, so it is just an image—there is no down or rollover state for it.

The behavior of the Image Field starts out the same as a standard Submit button—it submits the contents of the current form to the server for processing. However, it also sends additional data about where the user clicked on the image button in order to cause the submit to take place. This additional information is encoded into two additional variables named with the original image field name, but with a X and a Y on the end, and it contains the X and Y coordinates of the user's click in the image.

This information can be used for processing real-time image maps of images that are generated on-the-fly, or for guessing games in which the user must click somewhere on an image in order to win a prize.

The drawback to using image fields as buttons is that they don't offer the same level of feedback as traditional buttons, and they are difficult to maintain. Every time you want to change a button on your page, you have to edit the graphic of the button—not just edit its label. On a positive note, I find that graphical buttons are “prettier” and offer a friendlier browsing experience. They can be laid out on the screen precisely as you want them, rather than you relying on the browser to render a button with the same dimensions you happened to have in mind.

Although this is but a short introduction to forms, you shouldn't worry about not getting to use them later. We'll use make of the form objects once we reach the dynamic portions of this book.

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint