CGI-FormBuilder

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

  Data::FormValidator Support
    Thanks to another great patch from Peter Eichman, "Data::FormValidator"
    is supported as a validation option to "new()", just by passing it in as
    an object. See the documentation on "validate" for more information.

  Option sorting by LABELNAME or LABELNUM
    You can now sort options by "LABELNAME" or "LABELNUM", similar to the
    value-based sorting of "NAME" and "NUM". See the documentation for more
    details.

  XHTML Compliance
    Generated code now validates against <http://validator.w3.org>. This
    includes stuff like lowercase "get" and "post" methods, lowercase
    "onchange" and "onsubmit" actions, and so on.

VERSION 3.02
  Multi-Page Form Support
    A new module, "CGI::FormBuilder::Multi", has been added to handle the
    navigation and state of multi-page forms. A multi-page form is actually
    composed of several individual forms, tied together with the special CGI
    param "_page":

Changes  view on Meta::CPAN

  Compatibility Methods
    For compatibility with other modules, FormBuilder now includes
    "param()", "query_string()", "self_url()", and "script_name()".

VERSION 3.01
    This was a bugfix release, including the following changes:

        - fixed major problems with keepextras, including a reversed ismember test
        - added debug messages to keepextras and changed a few other debugs
        - added patch from Peter Eichman to fix scalar $field->tag and $field->tag_value
        - converted most all XHTML generation methods to only returning scalars
        - fixed the columns option which was totally broken for radio buttons
        - added a feature to plop in {border => 0} in columns as well
        - added the 2.x 'override' alias for field() 'force' which was missing
        - also added a 'defaults' alias for field() 'value' for CGI.pm happiness
        - more tests since there were way too many bugs

    In addition there were many documentation updates and changes.

VERSION 3.00
  Internals

Changes  view on Meta::CPAN

                        stylesheet => 1,        # turn on style
                   );
                
        print $form->render;

        # HTML will include
        #   <input class="myFBname" id="name" name="name" type="text" />
        #   <input class="myFBemail" id="email" name="email" type="text" />

  Compliant XHTML
    The output should be fully-compliant XHTML finally. Really. Maybe.

  Attributes and Field Objects
    Individual accessors have been added for every attribute that
    FormBuilder maintains. For example, here's a snippet of code to
    demonstrate:

        if ($form->stylesheet) {
            # loop thru fields, changing class
            for ($form->fields) {
                next if /_date$/;   # skip fields named "XXX_date"

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

    fieldname  => '_field',           # equiv of <tmpl_var field-tag>
    buttonname => '_button',
    errorname  => '_error',
    othername  => '_other',
    growname   => '_grow',
    statename  => '_state',
    extraname  => '_extra',
    dtd        => <<'EOD',            # modified from CGI.pm
<?xml version="1.0" encoding="{charset}"?>
<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="{lang}" xml:lang="{lang}">
EOD
);

# Which options to rearrange from new() into field()
our %REARRANGE = qw(
    options     options
    optgroups   optgroups
    labels      label

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

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

lib/CGI/FormBuilder/Field.pm  view on Meta::CPAN


    # attribute functions
    my $n = $f->name;         # name of field
    my $n = "$f";             # stringify to $f->name

    my $t = $f->type;         # auto-type
    my @v = $f->value;        # auto-stickiness
    my @o = $f->options;      # options, aligned and sorted

    my $l = $f->label;        # auto-label
    my $h = $f->tag;          # field XHTML tag (name/type/value)
    my $s = $f->script;       # per-field JS validation script

    my $m = $f->message;      # error message if invalid
    my $m = $f->jsmessage;    # JavaScript error message

    my $r = $f->required;     # required?
    my $k = $f->validate;     # run validation check

    my $v = $f->tag_value;    # value in tag (stickiness handling)
    my $v = $f->cgi_value;    # CGI value if any

lib/CGI/FormBuilder/Field.pm  view on Meta::CPAN


Returns the appropriate JavaScript validation code (see above).

=head2 label($str)

This sets and returns the field's label. If unset, it will be generated
from the name of the field.

=head2 tag($type)

Returns an XHTML form input tag (see above). By default it renders the
tag based on the type set from the top-level field method:

    $form->field(name => 'poetry', type => 'textarea');

However, if you are doing custom rendering you can override this temporarily
by passing in the type explicitly. This is usually not useful unless you
have a custom rendering module that forcibly overrides types for certain
fields.

=head2 type($type)

lib/CGI/FormBuilder/Util.pm  view on Meta::CPAN

    my $name = shift || return;
    my $attr = htmlattr($name, @_);     # ref return faster

    # see if we have a special tag name (experimental)
    (my $look = $name) =~ s#^(/*)##;
    $name = "$1$TAGNAMES{$look}" if $TAGNAMES{$look};

    my $htag = join(' ', $name,
                  map { qq($_=") . escapehtml($attr->{$_}) . '"' } sort keys %$attr);

    $htag .= ' /' if $name eq 'input' || $name eq 'link';  # XHTML self-closing
    return '<' . $htag . '>';
}

=head2 htmlattr($name, %attr)

This cleans any internal B<FormBuilder> attributes from the specified tag.
It is automatically called by C<htmltag()>.

=cut

pod/Changes.pod  view on Meta::CPAN

Thanks to another great patch from Peter Eichman, C<Data::FormValidator>
is supported as a validation option to C<new()>, just by passing it in
as an object. See the documentation on C<validate> for more information.

=head2 Option sorting by LABELNAME or LABELNUM

You can now sort options by C<LABELNAME> or C<LABELNUM>, similar to
the value-based sorting of C<NAME> and C<NUM>. See the documentation
for more details.

=head2 XHTML Compliance

Generated code now validates against L<http://validator.w3.org>.
This includes stuff like lowercase C<get> and C<post> methods, 
lowercase C<onchange> and C<onsubmit> actions, and so on.

=head1 VERSION 3.02

=head2 Multi-Page Form Support

A new module, C<CGI::FormBuilder::Multi>, has been added to handle the

pod/Changes.pod  view on Meta::CPAN

For compatibility with other modules, B<FormBuilder> now includes
C<param()>, C<query_string()>, C<self_url()>, and C<script_name()>.

=head1 VERSION 3.01

This was a bugfix release, including the following changes:

    - fixed major problems with keepextras, including a reversed ismember test
    - added debug messages to keepextras and changed a few other debugs
    - added patch from Peter Eichman to fix scalar $field->tag and $field->tag_value
    - converted most all XHTML generation methods to only returning scalars
    - fixed the columns option which was totally broken for radio buttons
    - added a feature to plop in {border => 0} in columns as well
    - added the 2.x 'override' alias for field() 'force' which was missing
    - also added a 'defaults' alias for field() 'value' for CGI.pm happiness
    - more tests since there were way too many bugs

In addition there were many documentation updates and changes.

=head1 VERSION 3.00

pod/Changes.pod  view on Meta::CPAN

               );
                
    print $form->render;

    # HTML will include
    #   <input class="myFBname" id="name" name="name" type="text" />
    #   <input class="myFBemail" id="email" name="email" type="text" />

=head2 Compliant XHTML

The output should be fully-compliant XHTML finally. Really. Maybe.

=head2 Attributes and Field Objects

Individual accessors have been added for every attribute that FormBuilder
maintains. For example, here's a snippet of code to demonstrate:

    if ($form->stylesheet) {
        # loop thru fields, changing class
        for ($form->fields) {
            next if /_date$/;   # skip fields named "XXX_date"

t/1d-messages.t  view on Meta::CPAN


unlink $messages;

# Check to ensure our lang and charset work correctly
{   local $TESTING = 0;
    ok($file->charset, 'iso-8859-1');
    ok($file->lang,    'en_US');
    ok($file->dtd, <<EOD);
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US">
EOD
    ok($file->charset('yo.momma'), 'yo.momma');
}

# Final test set is to just make sure we have all the keys for all modules
require CGI::FormBuilder::Messages::default;
my %need = CGI::FormBuilder::Messages::default->messages;
my @keys = sort keys %need;

t/2a-test04.html  view on Meta::CPAN

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title>Test</title>
 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
 <!-- JavaScript validation code -->
 
</head>
<body>

t/2a-test99.html  view on Meta::CPAN

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title>Test</title>
 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
 <!-- JavaScript validation code -->
 <tmpl_var js-head>
</head>
<body>

t/2e-test04.html  view on Meta::CPAN

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title>Test</title>
 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
 <!-- JavaScript validation code -->
 
</head>
<body>

t/2e-test99.html  view on Meta::CPAN

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title>Test</title>
 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
 <!-- JavaScript validation code -->
 <!--#echo var="js-head" -->
</head>
<body>



( run in 0.729 second using v1.01-cache-2.11-cpan-49f99fa48dc )