|
::Features
::Download
::Tutorial
::Examples
::Documentation ::FormBuilder Google Group ::Old List Archives ::Contribute |
|
Basic Tutorial - Step 4: Input Validation 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
$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 |
| FormBuilder is © Nate Wiger, with contributions from many people. |