Perl CGI::FormBuilder module for generating, validating, and processing HTML forms
Perl HTML Shell
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

CGI::FormBuilder - Perl module for easily generating and processing forms


Please see for online docs and tutorials. In addition, there is a google discussion group for help and patches.

Click here to lend your support to: formbuilder and make a donation at !


Use CPAN to install FormBuilder:

cpan CGI::FormBuilder

FormBuilder does not have any prerequisites; however, if you want to use templating support, you need to install one of:

  • HTML::Template
  • Text::Template
  • Template Toolkit
  • CGI::FastTemplate
  • CGI::SSI

Whichever you prefer to use.


use CGI::FormBuilder;

# Assume we did a DBI query to get existing values
my $dbval = $sth->fetchrow_hashref;

# First create our form
my $form = CGI::FormBuilder->new(
                name     => 'acctinfo',
                method   => 'post',
                stylesheet => '/path/to/style.css',
                values   => $dbval,   # defaults

# Now create form fields, in order
# FormBuilder will automatically determine the type for you
$form->field(name => 'fname', label => 'First Name');
$form->field(name => 'lname', label => 'Last Name');

# Setup gender field to have options
$form->field(name => 'gender',
             options => [qw(Male Female)] );

# Include validation for the email field
$form->field(name => 'email',
             size => 60,
             validate => 'EMAIL',
             required => 1);

# And the (optional) phone field
$form->field(name => 'phone',
             size => 10,
             validate => '/^1?-?\d{3}-?\d{3}-?\d{4}$/',
             comment  => '<i>optional</i>');

# Check to see if we're submitted and valid
if ($form->submitted && $form->validate) {
    # Get form fields as hashref
    my $field = $form->fields;

    # Do something to update your data (you would write this)
    do_data_update($field->{lname}, $field->{fname},
                   $field->{email}, $field->{phone},

    # Show confirmation screen
    print $form->confirm(header => 1);
} else {
    # Print out the form
    print $form->render(header => 1);


I'm aware that many Perl users are not familiar with git. This is ok. To submit a patch, just make changes to your local copy of FormBuilder and then create a unified diff:

vi   # make changes
diff -u >name_of_my_feature.diff

Then, just attach that diff to a bug report (see below).

Bug Reports

Please use github issues for any FormBuilder bugs or features. You will probably get a better response if you start by posting a message to the google group. Any issues posted to the horrific site will be IGNORED or rejected without comment.


Copyright (c) 2000-2011 Nate Wiger. All Rights Reserved.

This module is free software; you may copy this under the terms of the GNU General Public License, or the Artistic License, copies of which should have accompanied your Perl kit.

FormBuilder is maintained by a team of several, including Danny Liang, Wolfgang Radke, and Derek Wueppelmann. Your best bet for patches/support/etc is the google group.