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

Advanced Tutorial - Step 2: Intro to Templates Print

<< Remaining Features | HTML::Template >>

The basic idea behind any templating system is to keep the HTML layout separate from the CGI application. The HTML is placed in a template, which is then expanded by the templating module.

FormBuilder provides native support for the following engines:

If you're already familiar with any of these, you'll find FormBuilder can plug right into your existing templates.

Fully exploiting templates is probably deserving of its own tutorial. So, this will just give you a taste of what you can do. From there you should refer to the appropriate documentation on the template system of your choice.

Like anything else, enabling templates only requires one additional option to FormBuilder:

$form = CGI::FormBuilder->new(
             method => 'post',
             fields => \@fields,
             template => '/path/to/file.tmpl'
The above will enable HTML::Template style templates. If you want to make use of Template Toolkit, you must use a hashref so you can specify the type:
$form = CGI::FormBuilder->new(
             method => 'post',
             fields => \@fields,
             template => {
                 type => 'TT2',     # Template Toolkit
                 template => '/path/to/file.tmpl',
In fact, Template Toolkit accepts many other options, any of which can be specified within the template block above. Consult the Template Toolkit documentation for a list of options.

You can do the same thing with HTML::Template, just specify the type as HTML:

$form = CGI::FormBuilder->new(
             method => 'post',
             fields => \@fields,
             template => {
                 type => 'HTML',   # HTML::Template
                 filename => '/path/to/file.tmpl',
                 shared_cache => 1
Basically, if you specify a hashref to the template option, this hashref is passed directly to the template module, so it can accept any and all options the template module can natively.

In all cases, you don't change anything else! You address your form fields just like you would without a template. Your template is automatically expanded by FormBuilder when you say:

print $form->render;
Not to brag, but how cool is that!

<< Remaining Features | HTML::Template >>

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