[html-formfu] Perl DBI with FormFu

Carl Franks fireartist at gmail.com
Tue Mar 17 11:31:54 GMT 2009


2009/3/17 Manu Kaul <manu.kaul at gmail.com>:
> Hi,
> I am still trying to get my head around how FormFu works and still reading
> through the documentation to understand what is possible and what is not. So
> bear with me if I am not making sense :)
> But I want to be able to list out all the validations that are required on
> the form i.e. required fields, checking field lengths, checking field values
> against regular expressions, etc in the Config::General XML file. And then
> use that in my Catalyst project with FormFu.
> But instead of going   $form->create() or  $form->update... which will use
> FormFu::Model::DBIC I think, I want to be able to pass the form values to a
> custom method written in my Model class.
> Also was wondering how I can then display the DEFAULT values for a form when
> in EDIT mode, when I have a custom Model class in the background.
> Is it possible for you to provide me some sample code that caters to what I
> am doing or point me out some sample projects that are using FormFu so I can
> see how the configuration aspects of form validation will work. Then I can
> work on passing these off (once past validation) to my custom Perl DBI MODEL
> class.
> Hope this is making sense?

Check out HTML::FormFu::Model::HashRef which Moritz has been working on in svn
( /trunk/HTML-FormFu/ )

I think it'll provide both aspects - filling in the form from your
model - then providing the submitted values to pass to your model.

I think it would work something like this:

    my $form  = $c->stash->{form};
    my $model = $c->model('Foo');

    if ( $form->submitted_and_valid ) {
        $model->do_something_with_values(
            $form->model->create,
        );
    }
    elsif ( !$form->submitted ) {
        $form->model->default_values(
            $model->get_values,
        );
    }



More information about the HTML-FormFu mailing list