On Fri, Jan 20, 2006 at 01:07:46PM -0800, Terrence Brannon wrote:
Thanks for the feedback.
Still wondering about the name space, though.
> Is it Class::DBI dependant or does it use general Perl data structures
> for its work? I think HTML::Form is where most of these things go if
> they are generic, except for HTML::FillInForm, which might've been
> better named HTML::Form::FillIn
It's not Class::DBI dependent. It includes a module that adds
functionality.
If you create a for that is a subclass of Form::Base you just get
validation. If you subclass Form::Model::CDBI then you get
validation plus automatic population of single and multiple selects,
validation of those lookups and checks on unique fields. Automatic
update or create also also handled. And you get auto population of
data when first displaying the field.
Maybe someone would write Form::Model::DBIx::Class and it would do
the same thing. Or for any kind of store.
> > Fields can contain a form object,
>
> Hmm, the Perl oo modeling here is different from the HTML. HTML forms
> cant have forms as fields can they? Well, as long as it works
A form is just a collection of fields.
This for making compound fields. Say you have a timestamp in your
database table, but you want separate month, day, year drop down
selects. So you create a field called Form::Field:DMY. Then that
field creates a sub form that is made up of the three Integer fields
(or really make it from three other fields ::Year ::Day :Month).
> Just FYI, the HTML generation in CDBI::AsForm returns an HTML::Element
> instead of pure HTML so that the HTML can be easier manipulated. The
> old_style was pure HTML.
This module doesn't have any html generation in it. I do all of that
in Template Toolkit.
> >
> > # Catalyst Controller
> > package MyApplication::Controller::User;
> > use strict;
> > use MyApplication::Form::User;
> >
> > sub edit : Local {
> > my ( $self, $c, $id ) = @_;
> >
> > # Create the form object
> > my $form = MyApplication::Form::User->new( $id );
>
> so this does a MyApplication::Model::User->retrieve($id)
> is there some way to get at that? perhaps a 2 element list of
> ($form, $model) should be returned? or clearer as a hashref:
If $id is defined then it is fetched from the database, yes. The
model is hidden.
$item = $form->item;
What's not shown is in Catalyst's Application "end" action it does
looks for $c->stash->{form} and if so uses HTML::FillInForm to
populate the form.
> >
> > # Update the user record if form posted and form validates
>
> how about taint checking?
Might be nice to untaint for those that want it.
> are we looking at form fields names here or database column names?
> must the form field names correspond to database column names or can
> there be a transform to/fro?
Must be same.
> > sub validate_age {
> > my ( $self, $field ) = @_;
> > $field->add_error('Sorry, you must be 18')
>
> presumably add_error() indicates which field did not validate in the
> results hash? I presume the results hash is similar to dfv with
> missing, invalid
Well, add_error just adds an error to the field. To see if there's
any errors:
$form->has_errors;
There's no results hash.
$form->validate || die "didn't validate";
or $form->validate;
$form->has_erros && die "didn't validate";
--
Bill Moseley
[EMAIL PROTECTED]