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 9: Modules & mod_perl Print

<< JavaScript Actions 2 | Smartness >>

FormBuilder is designed to work well alone, alongside other modules, or even in a mod_perl environment. FormBuilder is written under use strict and is completely mod_perl safe.

The key to interacting with any of these situations is the params option to new(). We discussed this before, in the section on "Custom Headers". By default, FormBuilder assumes it has complete control of the CGI environment, and will create its own instance of to manage it.

However, when you're already using yourself, or running under mod_perl, this is obviously not true. So, in either of these situations you need to specify the params option to new().

First, using FormBuilder with


use CGI;
use CGI::FormBuilder;

$query = new CGI;
$form  = CGI::FormBuilder->new(
             method => 'post',
             fields => [qw/name email zipcode/],
             params => $query

print $form->render;
Second, using FormBuilder under mod_perl
package My::Application;    # or whatever

use Apache::Request;
use CGI::FormBuilder;

sub handler {
    my $r = Apache::Request->new(shift);
    my $form = CGI::FormBuilder->new(
                    method => 'post',
                    fields => [qw/name email zipcode/],
                    params => $r
    print $form->render;
In both situations, the only thing that you have to add is the params option. Everything else about FormBuilder stays the same.

Finally, note that the params and values options are separate, and both can be specified. The values option is designed to provide default values to populate the form with. The params option changes where to get CGI parameters from. CGI parameters will always override any default values.

<< JavaScript Actions 2 | Smartness >>

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