Drop-Down Menus
A drop-down menu gives the user a list of choices. Drop-down menus are often used to choose a state or country in a subscription form or to choose the color or size of a product.
Insert your cursor in the upper-right table cell of the "about you" fieldset. Click the List/Menu icon
in Insert panel (or Insert > Form > List/Menu).
Give the menu an ID of "birth_year" and a label of "birth
year" in the Input Tag Accessibility Attributes dialog.
A small drop-down menu will appear along with the "birth year" label. Select the label and drag it into the left table cell.

Select the drop-down menu and click the List Values button in the Property inspector to add the list items.

|
Make sure the Menu radio button is selected (we'll look at Lists shortly), then click List Values to enter the menu items. |
Add a few list items for the "birth year" drop-down menu. Give each entry an Item Label (the text the user will see for each choice) as well as a Value (the results you will receive).

|
Use the plus icon to add list items, and the minus icon to subtract items. |
Did you notice in my above example that I included an Item Label called "Select
One:"? I don't want my users to actually pick this, but it is a helpful reminder to choose an item from the menu rather than leave it
untouched.
To make sure "Select One:" is visible when the page first
loads, use the Initially selected option
in the Property inspector.

|

|
Select the list item that you would like to appear when the page first loads. |
Try out this drop-down menu to see another way to format a menu visually. This formatting method won't change how you receive the form results, but it will help to organize the items for the user:
Now look at the List Values for this drop-down menu:

|
Notice how simple punctuation helps to break up the menu so that the many choices are quicker to scan and select. |
List Boxes
List boxes bear a distinct similarity to drop-down menus. So much so that they share the same insert button, Property inspector options, and List Values window. The difference? A list box can be several lines long, and it allows for multiple choices if the user holds down the Ctrl key (PC) or Command key (Mac). In fact, it's helpful to remind the user of these keys with instructions such as "To make multiple selections, hold down your Ctrl key (PC) or Command key (Mac)."
Insert your cursor in the right column of the second row and click the List/Menu icon
in the Insert panel.
In the Input Tag Accessibility Attributes dialog, give the menu an ID of "interests" and a label of "what types of recipes interest you?"
Select the label and drag it over to the left cell.

Then click the List radio button in the Property inspector to make it a list menu rather than a drop-down menu.

Choose the number of visible lines with the Height option. Check "Allow Multiple" to allow users to select multiple items. The List Values dialog is handled the same way as the drop-down menu.

|
Notice the scroll bar in the above example. It
doesn't matter how many items are added to this list box—they
will only take up five lines of space. |
Text Areas
A text area is simply a multi-line text field. Text areas are useful for comments, message board posts, and other lengthy
typed responses.
Insert your cursor in the right column of the third row. Click the Text area button
in the Insert panel (or Insert > Form > Textarea). Give the text area an ID of "comments" and a label of "comments".
Select the "comments" label and drag it over to the left cell.
The width of the text area is dictated by the Char width field in the Property inspector. Change this value to "30".

|
Always allow a little extra space to the right
of the text area—the character width may vary depending on the
user's default font size. |
The height of the text area is set by a property called Num
Lines (number of lines). If the user types beyond the allotted
space, scrollbars will appear.

|
Even though I have chosen a visual area of 30
characters wide by five lines tall, the amount of text the user
can enter is unlimited and scrollbars will appear if needed. |
This fieldset is finished—ready for the next set of elements?
Checkboxes
Checkboxes are
used to allow selection of multiple options. To remind a user of this functionality, "Check all
that apply:" is often used to introduce a series of checkboxes.
Click inside the upper-right cell of the "newsletters" table. We will use a nested fieldset in this cell to contain a series of checkboxes. Choose the Fieldset button
(or Insert > Form > Fieldset) to insert a new fieldset. Enter "sign me up for the following newsletters:" into the Legend field.
Press your right arrow key to move your cursor to the right of the legend. Then click the Checkbox button
in the Insert panel or choose Insert > Form > Checkbox. Give the checkbox an ID of "daily_dish" and a label of "daily dish".
Press Shift-Return to create a line break, then insert another check box
with an ID of "cooking_news" and a label of "cooking news".
Press Shift-Return again to insert a third check box. Give it an ID of "recipe_notes" and
a label of "recipe notes". Done!

Radio Buttons
Radio buttons are used in groups of two or more to retrieve mutually exclusive data. Only one option can be selected. Clicking one radio button in the group turns off all the others. Try it here:
Click your cursor inside the second row, right column of the "newsletters" table. Choose the Fieldset button
(or Insert > Form > Fieldset) to insert a new fieldset. Enter "please send occasional email updates" as the fieldset legend.
Press your right arrow key to move your cursor to the right of the legend, then click the Radio Button icon in the Insert panel
or go to Insert > Form > Radio Button. Give the radio button an ID and checked value of "yes". Then hit Shift-Return and add another radio button with an ID and value of "no".

After creating both buttons, make sure that they are both assigned the name "updates" in the left field of the Property inspector. When several radio buttons have the same name, they are part of the same group. If you plan to have two or more sets of radio buttons, each set should have a different name so they don't exclude each other's choices.
 |

|
Both the "yes" and "no" radio buttons have the same name. This tells the browser that they are part of the same group. |
Another way to create a group of radio buttons is with the Radio Group option
in the Insert panel. This opens a dialog in which you can program all of your radio buttons at once to avoid any naming mistakes.
Buttons
In order to submit a form, you'll need a Submit button that
tells the data where to go (this is where the back-end processing comes
in, which we'll discuss soon).
Many forms also contain Reset buttons to clear all the data, but many users find this to be redundant or confusing (wouldn't you hate to accidentally click Reset after filling out a long form instead of clicking Submit)?
Insert your cursor in the last row, right column of the nested table and click the Button icon
in the Insert panel, or Insert > Form > Button. Enter "submit" in the ID field and leave the label blank. Also, select No label tag from the style menu.

|
Buttons don't require a separate label. |
The button label is determined by the Value field in the Property inspector. You can enter any label you like, just make sure that it clearly explains what the button will do.

|
When you insert a button, it has a "Submit form" action by default and is labeled "Submit." Selecting "Reset form" or "None" will change its action as well as its label. |
The most important feature of a button is its action. You can't re-label a Reset button with the name "Submit" and expect it to submit the form. You must choose the correct action using the radio buttons in the Property inspector. Let's examine each action:
 |
|
 |
| |
Submit form: This button submits the data to the form handler.
Reset form: This button clears all of the data entered in the form by the user.
None: On its own, this button will do absolutely nothing when clicked. That's right, nothing! However, special code can be added to the form to give a None button special attributes—for example, you can select the button and apply a behavior such as a form validation script. |
|
 |
|
 |
Buttons look like gray boxes in Windows or blue/clear "jellybeans" on
Mac OS X. These standard buttons are the best bet since they
are familiar and conventional. However, if you want to use a custom image button so it meshes better with your design, Dreamweaver
gives you this option.
To add an image submit button, click the Image Field icon in the Insert panel
or go to Insert > Form > Image Field. You can then browse for an image on your hard drive. The image will automatically be given "Submit form" properties and there will be a dotted line around the image so you know it is an image Submit button rather than a regular image. That's it—the "Submit form" action and the form handler code will take care of the rest.
Final Design Adjustments
One more detail to finish up. Previewing the form in a browser, you might notice that there is a lot of space around the nested fieldsets.

|
There is too much space surrounding the nested fieldsets. Also, the borders might be overkill. |
This is easy to modify using CSS. Create a new CSS rule, choosing the Compound selector type (Dreamweaver CS3 users: choose "Advanced"). Type fieldset fieldset into the
Selector Name field. This is a descendant selector that means "select
any fieldset that is nested inside another fieldset".

|
This descendant selector only applies to nested fieldsets. The main fieldsets will not be affected. |
In the Box category, set the margins and padding to "0" (same for all). In the Border category, set the border style to "none" (same for all). Click OK. Preview in a browser to see how it looks.

|
The margins, padding, and borders have been removed from the nested fieldsets. |
Other Form Elements
There are a few other form elements in the Insert panel. You won't use them often, but you should know what they do.
 |
|
 |
| |
Hidden Field: Hidden fields are used to provide important data to the server without the user seeing it. For example, each time a form is sent to the Webmaster as an email (rather than to a database), the form needs to know the Webmaster's email address. You'd enclose this data in a hidden field so it is transmitted without the user seeing it.
File Field: This adds a field and Browse button to a form so that the user can upload a file to your server or send one to you as an attachment. Using such a field requires some complex scripting on your part (or your tech person's part!) and a server that can accept files from outside sources.
Jump Menu: A Jump Menu is used for drop-down menu navigation bars rather than drop-down menu form inputs. Using a Jump Menu, you can add navigation options to a drop-down menu. After selecting an option, the user is sent to a specified hyperlink. |
|
 |
|
 |
You'll want to know what these icons are: 
These icons look just like their text field, textarea, checkbox, and
drop-down menu counterparts, but the orange starburst seems to indicate
some kind of special power. Let's try them out to see how they work.
Open the form_spry.html file from the recipetree folder.
A fieldset and table have been set up for you. Click inside the upper-right
cell of the table, then choose the Spry Validation Text Field icon
from
the Insert panel, or Insert > Form > Spry
Validation Text Field.
The Input Tag Accessibility Attributes dialog
looks the same as always. Insert a label and ID—for example, "name". Choose the "Attach label tag" option, and click OK to exit the dialog.
If you mouse over the text field in the Document window, you'll notice
a blue tab that identifies it as a Spry text field.

Let's get the label and form element positioned properly in the table.
Click your cursor inside the label, then use the Tag
selector to select the <label> tag. Drag and drop into the left
cell.

Save and preview in a browser. Don't fill anything into the
name field—just click the "Submit" button. Sure enough,
a message will pop up stating that this is a required field.

Let's go back to Dreamweaver to see how this magic works.
If you select the text field, you'll see the regular text field properties
in the Property inspector. However, if you click the blue tab, the
Property inspector will show the Spry properties.

Lots of goodies here:
 |
|
 |
| |
The Type menu
allows you to validate against a certain type of data, for example,
the data must be formatted as an email address, a credit card number,
a phone number, or a URL. If you just want the field to be completed
but don't have a specific requirement regarding the format, like
in our name example, leave the type set to "None".
It is helpful to give users a hint for
how to enter the data. For example, a hint for "date of
birth" might read "MM/DD/YYYY".
The Validate on checkboxes determine
when the validation process will occur: Blur (as
soon as the user clicks outside the field), Change (as
the user changes text inside the field), or Submit (when
the user tries to submit the form).
The Preview states menu allows
you to preview how the field will look in its valid or required
states.
If you want to go easy on your users, uncheck Required.
Your users will get the same validation prompts, but they will
be able to submit the form even if it isn't perfectly filled
out.
|
|
 |
|
 |
Choose Required from the Preview states menu in the Property inspector. If your user forgets to fill in this field, he or she will get a default error message "A value is required." Enter something more user friendly, like "Please enter your name."

The Spry Validation Textarea, Checkbox,
and Select widgets work much the same way.
Try them out—insert one of each and play around with the settings.
Each validation widget comes with an external style sheet.
You might decide to change the background color of the valid state to
blue instead of green, or maybe you want the error message text to appear
in a darker shade of red.

Dreamweaver CS4 users have three additional Spry validation widgets:

The Validation Password widget enforces rules for passwords. For example, you could require all passwords to contain a minimum of five characters. If your user enters four characters, he or she will get an error:

If your user is setting up a new account, you might want to use a Validation Confirm widget. After creating a new password, ask the user to retype the password. If the user fails to type the exact same password, the widget returns an error message stating that the values do not match. This will prevent any potential password errors—maybe your user thought he typed "tomato", but really, he typed "tomatoo".

The Validation Radio Group widget requires that the user make a selection from a group of radio buttons

Tables are a practical way to organize form elements, but CSS fanatics
might want to use divs instead. Let's explore this now. Open form_tableless.html from
the recipetree folder.
Click inside the "user name and password" fieldset. Go to Insert > Layout
Objects > Div Tag. Give the div a class of "required" and click OK.

The new div appears in the fieldset. The yellow div outline is hard to see against the pale background. Be careful as you insert the form element into the div.
First, press the right arrow key on your keyboard to move your cursor to the right of the 'Content
for class "required" Goes Here' filler text.

Click the Text Field button
in
the Insert panel (or Insert > Form > Text
Field) to insert a text field into the div.

And finally, delete the 'Content
for class "required" Goes Here' filler text.

Let's create a few styles to format what we've got here.
Start with the div—create a new CSS Rule and choose the Compound selector type (or Advanced in CS3). Type form
div into the Selector Name field. This is a descendant selector that
will style divs within the form area.

In the Box category, set clear to "both" (this
will force each div to appear in separate rows), padding to "5" (this
will add some padding inside the div), and margin to "5" (this
will add a margin between the divs). Click OK.
Remember that we gave this div a class of "required".
This will allow us to apply special formatting to the required form element
labels. Create a new CSS rule and type form div.required into
the Selector Name field. This rule will apply to any div with a class of "required"
inside the form area.

In the Type category, set
the font weight to "bold" and click OK.
We will also create an optional class style for the optional
form elements. Create a new CSS rule and type form
div.optional into the Selector Name field. This will select any div
with a class of optional within the form area.

The optional form element labels should be set to "normal" font-weight.
One more element to style: labels. Create a new rule for form
div label. This will style any label inside a div inside the
form area.

In the Box category, set
the labels to float "left" (this
turns the label into a block element and pushes it to the left) and set
the width to 150 pixels (this will create
a column effect). Uncheck "same for all" under padding and
add 5 pixels of right padding.
In the Block category, set
the text-align to "right". This
will right-align the labels against the form elements. Click OK and see
how it looks.

Click below
the div, then go to Insert > Layout Objects > Div
Tag to insert another div. Choose a class of "required" from
the Class menu in the Insert Div Tag dialog.

Insert a "password" text field with a label of "password" into the new div.
To finish up this fieldset, insert a third div with a class of "required". You'll need another text field labeled "email address".

As you can see, aligning text fields with CSS is quite easy. However, it gets a little trickier when you add checkboxes.
Click inside the "newsletters" fieldset and insert a new div, choosing "optional" from
the Class menu in the Insert Div Tag dialog.
Insert a checkbox with a label of "sign me up".

|
Checkboxes and radio buttons
require extra formatting.
|
This might look a little out of whack. The checkbox label,
normally placed to to right of the checkbox, is pushed over 150 pixels
due to the form div label selector we created
earlier.
To override this, create a new CSS rule called .radiolabel.
This class selector can be applied to check box and radio button labels
to shift them back into place.

In the Block category, set
the text-align to "left" and display to "inline".
This will left-align the labels next to the check box.
In the Box category, set float to "none".
This overrides the "left" float on the form
div label selector. Click OK.
Select the "sign me up" label (click inside the
label, then use the Tag selector to click the <label> tag). Then
apply the .radiolabel style. Problem solved.

This worked great on the check box, so let's try a radio group. Insert a div with a class of "required". Click inside the new div and insert a fieldset (radio button groups look nicer nested inside their own fieldsets). Give the fieldset a legend of "please send
occasional e-mail updates" and click OK.
The new fieldset will appear in the Document window. Click your right arrow key to move your cursor to the right of the fieldset legend, then click the radio group button in the Insert panel.
Name the
radio group "email_updates" (this will identify the group
in your form results but won't display in the browser) and add "yes" and "no" labels
and values.

The labels will be staggered at first:

Select the "yes" label and apply the .radiolabel style
to push it into place. Repeat with the "no" label.

As a final touch, you could edit the fieldset
fieldset rule and add a 150 pixel left margin (so it lines up with the column of
text field form elements). Any additional formatting adjustments are up to you!