CGI-FormBuilder

 view release on metacpan or  search on metacpan

pod/Changes.pod  view on Meta::CPAN

                     # first args are hashrefs per-form
                     \%form1_opts,
                     \%form2_opts,
                     \%form3_opts,

                     # remaining options apply to all forms
                     header => 1,
                     method => 'POST',
                );

    my $form = $multi->form;    # current form

    if ($form->submitted && $form->validate) {

        # you write this
        do_data_update($form->fields);

        # last page?
        if ($multi->page == $multi->pages) {
            print $form->confirm;
            exit;
        }

        $multi->page++;          # next page counter
        $form = $multi->form;    # fetch next page's form
    }
    print $form->render;

For more details, see L<CGI::FormBuilder::Multi>.

=head2 External Source File

Inspired by Peter Eichman's C<Text::FormBuilder>, the new C<source>
option has been added to C<new()> which enables the use of an external
config file to initialize B<FormBuilder>. This file takes the format:

    # sample config file
    method: POST
    header: 1
    submit: Update, Delete

    fields:
        fname:
            label: First Name
            size:  50
            validate: NAME
        lname:
            label: Last Name
            size:  40
            validate: NAME
        sex:
            label:    Gender
            options:  M=Male, F=Female
            jsclick:  javascript:alert("Change your mind??");
            validate: M,F

    required: ALL

    messages:
        form_invalid_text:  Please correct the following fields:
        form_required_text: Please fill in all <b>bold</b> fields.

You can even pre-parse this file, and generate a module from it
which you can then reuse in multiple scripts using the C<write_module()>
function. For more details, see L<CGI::FormBuilder::Source::File>.

=head2 "Other" Fields

The new C<other> option has been added to C<field()>. If specified,
a text box will be added to the right of the field, and its value
will be used if the main field is not filled in. It will be subject
to the same required and validation checks as the main field:

    $form->field(name     => 'favorite_color',
                 options  => [qw(Red Green Blue)],
                 validate => 'NAME',
                 other    => 1);     # allow "other"

This would create HTML something like this:

    Favorite Color: []Red []Green []Blue []Other: [____________]

The text "Other:" is controlled by the message C<form_other_default>.

=head2 Growable Fields

Thanks to a patch from Peter Eichman, C<field()> now also accepts
a C<growable> option. This option enables some JavaScript hooks
that add an "Additional [label]" button on text and file fields:

    Data File: [______________] [Additional Data File]

When you click on the "Additional Data File" button, another box will be
appended, allowing you to add more files. The values are then retrieved
in the usual fashion:

    my @files = $form->field('data_file');

Like "other" fields, all elements are subject to validation checks. The
text "Additional %s" is controlled by the message C<form_grow_default>.

=head2 Support for C<CGI::FastTemplate>

Thanks once again to Peter Eichman (busy guy), the module C<CGI::FormBuilder::Template::Fast>
has been included. This adds the template type C<Fast> as an interface
to C<CGI::FastTemplate>:

    my $form = CGI::FormBuilder->new(
                    template => {
                        type => 'Fast',
                        define => {
                            form  => 'form.tmpl',
                            field => 'field.tmpl',
                        }
                    }

See L<CGI::FormBuilder::Template::Fast> for more details. Thanks again
Peter!

=head2 Subclassable Templates and tmpl_param()



( run in 0.784 second using v1.01-cache-2.11-cpan-437f7b0c052 )