Class::DBI::FormBuilder 0.481 review

Download
by rbytes.net on

Class::DBI::FormBuilder is a Perl module with Class::DBI/CGI::FormBuilder integration. SYNOPSIS package Film; use stri

License: Perl Artistic License
File size: 44K
Developer: David Baird
0 stars award from rbytes.net

Class::DBI::FormBuilder is a Perl module with Class::DBI/CGI::FormBuilder integration.

SYNOPSIS

package Film;
use strict;
use warnings;

use base 'Class::DBI';
use Class::DBI::FormBuilder;

# for indented output:
# use Class::DBI::FormBuilder PrettyPrint => 'ALL';

# POST all forms to server
Film->form_builder_defaults->{method} = 'post';

# customise how some fields are built:
# 'actor' is a has_a field, and the
# related table has 1000's of rows, so we don't want the default popup widget,
# we just want to show the current value
Film->form_builder_defaults->{process_fields}->{actor} = 'VALUE';

# 'trailer' stores an mpeg file, but CDBI::FB cannot automatically detect
# file upload fields, so need to tell it:
Film->form_builder_defaults->{process_fields}->{trailer} = 'FILE';

# has_a fields will be automatically set to 'required'. Additional fields can be specified:
Film->form_builder_defaults->{required} = qw( foo bar );



# In a nearby piece of code...

my $film = Film->retrieve( $id );
print $film->as_form( params => $q )->render; # or $r if mod_perl

# For a search app:
my $search_form = Film->search_form; # as_form plus a few tweaks


# A fairly complete mini-app:

my $form = Film->as_form( params => $q ); # or $r if mod_perl

if ( $form->submitted and $form->validate )
{
# whatever you need:

my $obj = Film->create_from_form( $form );
my $obj = Film->update_from_form( $form );
my $obj = Film->update_or_create_from_form( $form );
my $obj = Film->retrieve_from_form( $form );

my $iter = Film->search_from_form( $form );
my $iter = Film->search_like_from_form( $form );
my $iter = Film->search_where_from_form( $form );

my $obj = Film->find_or_create_from_form( $form );
my $obj = Film->retrieve_or_create_from_form( $form );

print $form->confirm;
}
else
{
print $form->render;
}

# See CGI::FormBuilder docs and website for lots more information.

Errata: use of column name/accessor/mutator is currently broken if your column accessors/mutators are different from the column name. The documentation is also broken w.r.t. this.

This module creates a CGI::FormBuilder form from a CDBI class or object. If from an object, it populates the form fields with the object's values.

Column metadata and CDBI relationships are analyzed and the fields of the form are modified accordingly. For instance, MySQL enum and set columns are configured as select, radiobutton or checkbox widgets as appropriate, and appropriate widgets are built for has_a, has_many and might_have relationships. Further relationships can be added by subclassing. has_a columns are set as 'required' fields in create/update forms.

Requirements:
Perl

Class::DBI::FormBuilder 0.481 search tags