Perl Form Builder ::Features ::Download ::Tutorial ::Examples
::Documentation ::FormBuilder Google Group ::Old List Archives ::Contribute
Note: The mailing list is has been replaced by the Google FormBuilder Group


1. Intro to FormBuilder
2. A Simple Form
3. Form Method
4. Input Validation
5. Field Options
6. Multi-Select Lists
7. Field Data
8. Field Attributes
9. HTML Formatting
10. Custom Headers
S. Summary


1. Trickier Forms
2. Perl References
3. Default Values
4. CGI Stickiness
5. JavaScript Actions
6. Input Validation 2
7. Multiple Submits
8. JavaScript Actions 2
9. Modules & mod_perl
10. Smartness
S. Summary


1. Remaining Features
2. Intro to Templates
3. HTML::Template
4. HTML::Template 2
5. Template Toolkit
6. Exploiting render()
7. Multi-Screen Apps
8. Multi-Screen Apps 2
9. Multi-Screen Apps 3
10. Custom Messages
S. Summary

Basic Tutorial - Step 4: Input Validation Print

<< Form Method | Field Options >>

If you played with the simple form a little, you noticed that it let you enter anything for any of the fields. Obviously what we really want is to be able to make sure that our input is indeed valid; that the person entered a real email address, actual phone number, and so forth.

This is where FormBuilder's validation routines come in. FormBuilder will actually generate both JavaScript and Perl regex functions on the fly, which will automatically check your data.

Using validation is simple - all you have to do is specify the validate option to new(). So, modifying our simple form we add:

$form = CGI::FormBuilder->new(
             fields => \@fields,
             validate => {
                first_name => 'NAME',
                last_name  => 'NAME',
                email      => 'EMAIL',
                phone      => 'PHONE',
Our new validate block (actually a hashref) tells FormBuilder to use its built-in NAME, EMAIL, and PHONE regular expressions to validate the form. Here is a full list of built-in patterns. In addition, you can specify your own regexps, which we'll look at later.

Pause to see this in action, as well as view the HTML generated, before continuing.

As you can see, FormBuilder does a lot of work for you. In just 25 lines, we already have a form application complete with validation. Plus, adding a new field is as simple as adding another element to our @fields array. FormBuilder will automatically re-layout the form and properly handle the data.

<< Form Method | Field Options >>

FormBuilder is © Nate Wiger, with contributions from many people.