[Catalyst] Any recommendations for multiple forms in catalyst (have been using HTML::FormFu)?

Carl Franks fireartist at gmail.com
Fri Jul 4 08:38:17 BST 2008


2008/7/4  <kakimoto at tpg.com.au>:
> Hello Carl,
>  Thanks for that. Sounds good but a few questions to ask.
>
> 1) I have read through the Actions section in
> http://search.cpan.org/~zarquon/Catalyst-Manual-5.7012/lib/Catalyst/Manual/Intro.pod#Actions
> and yet I couldn't really find anything that describes what the third
> argument in
> "sub form2 : Path : FormMethod('_build_form2')" means. In that, I meant,
> "FormMethod('_build_form2')".

I'll provide brief answers - if you want, repost to the formfu mailing
list [1] so we don't waste the good Catalyst folk's time.

When you referred to `$form->stash->{form}` I perhaps wrongly guessed
you were using Catalyst-Controller-HTML-FormFu and the FormConfig
action.

FormMethod is documented in Catalyst-Controller-HTML-FormFu [2]

In a nutshell, FormMethod('_build_form') does this:

    my $form = HTML::FormFu->new;
    $form->populate(
        $controller->_build_form($c)
    );
    $form->process( $c->request );
    $c->stash->{form} = $form;

> 2) From sub build_form_2, you mentioned that
>>     # return hash-ref based on $c->req->params->{loan_type}
>>     # automatically gets passed to $form->populate
>
> Is it possible for me to:
>  a) load_config_file() of a certain file which I define (for example,
> "home_loans.yml")
>  b) and return  the form object that has just runned load_config_file
> (as per the step above)?

Something like this would work:

sub _build_form {
    my ( $self, $c ) = @_;

    my $value = $c->req->param->{loan_type}
        or die "loan_type required";

    my $file;

    if ( $value eq 'foo' ) {
        $file = 'foo.yml';
    }
    elsif ( $value eq 'bar' ) {
        $file = 'bar.yml';
    }
    else {
        die "invalid loan_type";
    }

    $file = $c->path_to('root', 'forms', $file);

    return {
        load_config_file => "$file",
    };
}


[1] http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
[2] http://search.cpan.org/~cfranks/Catalyst-Controller-HTML-FormFu-0.03000/lib/Catalyst/Controller/HTML/FormFu.pm#SYNOPSIS



More information about the Catalyst mailing list