[html-formfu] DBIC::Validation::FormFu RFC & Element::Date patch

Zbigniew Lukasiak zzbbyy at gmail.com
Thu Oct 18 17:44:31 GMT 2007


Hi Jonas,

How about moving the the validation from the DB layer code into some
separate class in HTML::FormFu hierarchy?  I hate it when I have to
add things to the DB model that belong to the form layer this makes
the model coupled to the form - and I would rather have a clean model
independend on what form processing layer I use.

Cheers,
Zbyszek

On 10/18/07, Jonas Alves <jonas.alves at gmail.com> wrote:
> Hi all,
> I wrote a DBIx::Class::Validation subclass to use FormFu to do DBIC
> validation. And I would like your comments on it.
> The syntaxe is like this:
>
> # On you DBIC class
> __PACKAGE__->load_components(qw/Validation::FormFu Core/);
> __PACKAGE__->validation(
>     forms_dir => '/path/to/MyApp/root/forms/',
>     formfu_config => 'user.yml',
>     filter     => 1,
>     formfu_args => {
>         query_type => 'Catalyst',
>         render_class_args => {
>             ENCODING => 'UTF-8',
>             INCLUDE_PATH => '/path/to/MyApp/root/formfu',
>         },
>     }
> );
> # formfu_config defaults to "$table_name.yml"
>
> #On your Controller
> sub create : Local {
>     my ( $self, $c ) = @_;
>     my $user;
>
>    eval {
>         $user =
> $c->model('DBIC::User')->create($c->req->params);
>         $c->redirect(...); # redirect to a "user created successfully" page
>     };
>     if (blessed $@ && $@->isa('HTML::FormFu')) {
>         $c->error(0); #clear errors
>         $c->stash(form => $@); # put the form on the stash to be redisplayed
> with errors filled
>     }
> }
>
> Comments?
>
> The only problem I had was with Element::Date. By default E::D params are
> returned like this:
> {
>     'date.day' => 1,
>     'date.month' => 1,
>     ' date.year' => 2007,
> }
> But it looks like that DBIC deletes all parameters with a dot in the name so
> I used C::Plugin::Params::Nested
> to turn the params into this:
> {
>     date => {
>         day => 1,
>         month => 2,
>         year => 2007,
>     }
> }
> I wrote a patch to Element::Date to accept this struct as input too. This
> patch goes attached.
> Then FormFu inflates the field and pass it to DBIC as { date => '2007-01-01
> 00:00:00' }, perfect to be inserted in the database. :)
> I need to create some tests and then I can post the dist to the list if
> someone has interest.
>
> Cheers,
> --
> Jonas
>
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.rawmode.org
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>
>


-- 
Zbigniew Lukasiak
http://brudnopis.blogspot.com/



More information about the HTML-FormFu mailing list