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

Intermediate Tutorial - Step 2: Perl References Print

<< Trickier Forms | Default Values >>

This really doesn't belong here, but there are very few concise explanations of references in Perl, and understanding them will really help you exploit FormBuilder.

Up until now, we've skirted the idea of references, mentioning in passing that you should just place a backslash in front of any arrays or hashes you need to pass into FormBuilder.

Doing so actually creates a reference. Taking a reference allows you to pass arrays and hashes around as scalars (singular values), which is needed in Perl 5 to keep them intact. In the examples, you've seen something similar to this:

@fields = qw(name email);
$form = CGI::FormBuilder->new(
             fields => \@fields
Here, \@fields is a reference. Specifically, it's an array reference, or "arrayref" for short. Similarly, we can do the same thing with hashes:
%validate = (
    name  => 'NAME';
    email => 'EMAIL',

$form = CGI::FormBuilder->new(
             fields   => \@fields,
             validate => \%validate
Here, \%validate is a hash reference, or "hashref".

There are two more types of references: "anonymous arrayrefs" and "anonymous hashrefs". These are created with [] and {}, respectively. For our purposes, there is no real difference between this code:

@fields = qw(name email);
%validate = (name => 'NAME', email => 'EMAIL');

$form = CGI::FormBuilder->new(
             fields   => \@fields,
             validate => \%validate
And this code:
$form = CGI::FormBuilder->new(
             fields   => [ qw(name email) ],
             validate => { name => 'NAME', email => 'EMAIL' }
Except that the latter doesn't require that we first create @fields and %validate variables.

Now back to our regularly-scheduled program...

<< Trickier Forms | Default Values >>

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