CGI-FormBuilder

 view release on metacpan or  search on metacpan

lib/CGI/FormBuilder.pod  view on Meta::CPAN

        print $form->render(header => 1);
    }

=head1 DESCRIPTION

If this is your first time using B<FormBuilder>, you should check out
the website for tutorials and examples at L<http://formbuilder.org>.

You should also consider joining the google group at 
L<http://groups.google.com/group/perl-formbuilder>.
There are some pretty smart people on the list that can help you out.

=head2 Overview

I hate generating and processing forms. Hate it, hate it, hate it,
hate it. My forms almost always end up looking the same, and almost
always end up doing the same thing. Unfortunately, there haven't
really been any tools out there that streamline the process. Many
modules simply substitute Perl for HTML code:

    # The manual way
    print qq(<input name="email" type="text" size="20">);

    # The module way
    print input(-name => 'email', -type => 'text', -size => '20');

The problem is, that doesn't really gain you anything - you still
have just as much code. Modules like C<CGI.pm> are great for
decoding parameters, but not for generating and processing whole forms.

The goal of CGI::FormBuilder (B<FormBuilder>) is to provide an easy way
for you to generate and process entire CGI form-based applications.
Its main features are:

=over

=item Field Abstraction

Viewing fields as entities (instead of just params), where the
HTML representation, CGI values, validation, and so on are properties
of each field.

=item DWIMmery

Lots of built-in "intelligence" (such as automatic field typing),
giving you about a 4:1 ratio of the code it generates versus what you
have to write.

=item Built-in Validation

Full-blown regex validation for fields, even including JavaScript
code generation.

=item Template Support

Pluggable support for external template engines, such as C<HTML::Template>,
C<Text::Template>, C<Template Toolkit>, and C<CGI::FastTemplate>.

=back

Plus, the native HTML generated is valid XHTML 1.0 Transitional.

=head2 Quick Reference

For the incredibly impatient, here's the quickest reference you can get:

    # Create form
    my $form = CGI::FormBuilder->new(

       # Important options
       fields     => \@array | \%hash,   # define form fields
       header     => 0 | 1,              # send Content-type?
       method     => 'post' | 'get',     # default is get
       name       => $string,            # namespace (recommended)
       reset      => 0 | 1 | $str,            # "Reset" button
       submit     => 0 | 1 | $str | \@array,  # "Submit" button(s)
       text       => $text,              # printed above form
       title      => $title,             # printed up top
       required   => \@array | 'ALL' | 'NONE',  # required fields?
       values     => \%hash | \@array,   # from DBI, session, etc
       validate   => \%hash,             # automatic field validation

       # Lesser-used options
       action     => $script,            # not needed (loops back)
       cookies    => 0 | 1,              # use cookies for sessionid?
       debug      => 0 | 1 | 2 | 3,      # gunk into error_log?
       fieldsubs  => 0 | 1,              # allow $form->$field()
       javascript => 0 | 1 | 'auto',     # generate JS validate() code?
       keepextras => 0 | 1 | \@array,    # keep non-field params?
       params     => $object,            # instead of CGI.pm
       sticky     => 0 | 1,              # keep CGI values "sticky"?
       messages   => $file | \%hash | $locale | 'auto',
       template   => $file | \%hash | $object,   # custom HTML

       # HTML formatting and JavaScript options
       body       => \%attr,             # {background => 'black'}
       disabled   => 0 | 1,              # display as grayed-out?
       fieldsets  => \@arrayref          # split form into <fieldsets>
       font       => $font | \%attr,     # 'arial,helvetica'
       jsfunc     => $jscode,            # JS code into validate()
       jshead     => $jscode,            # JS code into <head>
       linebreaks => 0 | 1,              # put breaks in form?
       selectnum  => $threshold,         # for auto-type generation
       smartness  => 0 | 1 | 2,          # tweak "intelligence"
       static     => 0 | 1 | 2,          # show non-editable form?
       styleclass => $string,            # style class to use ("fb")
       stylesheet => 0 | 1 | $path,      # turn on style class=
       table      => 0 | 1 | \%attr,     # wrap form in <table>?
       td         => \%attr,             # <td> options
       tr         => \%attr,             # <tr> options

       # These are deprecated and you should use field() instead
       fieldtype  => 'type',
       fieldattr  => \%attr,
       labels     => \%hash,
       options    => \%hash,
       sortopts   => 'NAME' | 'NUM' | 1 | \&sub,

       # External source file (see CGI::FormBuilder::Source::File)
       source     => $file,
    );



( run in 0.736 second using v1.01-cache-2.11-cpan-9581c071862 )