Validating Forms

It can be frustrating to look over feedback that’s been submitted via a form on your Web page, only to notice that your visitor failed to provide a name, email address, or some other piece of critical information. That’s why, depending on the type of form, you might want to make certain information mandatory.

For example, a form used for subscribing to an email newsletter isn’t much use if the would-be reader doesn’t type in an email address for receiving it. Likewise, if you need a shipping address to deliver a brochure or product, you’ll want to be sure that the user included her address on the form.

Luckily, Dreamweaver provides a Behavior—a ready-made JavaScript program—that accomplishes this exact task. Called Validate Form, this Dreamweaver behavior alerts users when they haven’t filled out a form properly. You can specify that a particular field can’t be left blank, or that it must contain numbers only, or that it must contain a proper email address. If someone attempts to submit the form without the correct information, a small dialog box pops up identifying the mistake. You’ll no longer receive blank forms.

Unfortunately there’s a built-in limitation to this Dreamweaver behavior: You can only validate text fields. In other words, you can’t check to see if a user clicked a particular checkbox or made a selection from a pull-down menu. Nor can you see if they chose a file to upload or clicked a radio button.

Nonetheless, the Validate Form behavior is a great ...

Get Dreamweaver MX: The Missing Manual now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.