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

kakimoto at tpg.com.au kakimoto at tpg.com.au
Fri Jul 4 00:00:46 BST 2008


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')".

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)?


Any sites you could point me to read in reference to the first question
would be great.

 Thanks!

kakimoto




Quoting Carl Franks <fireartist at gmail.com>:

> 2008/7/3  <kakimoto at tpg.com.au>:
> >
> > hello all :)
> >
> >  i;m trying to build a system with catalyst. Followed the tutes
> and
> > used html::FormFu. Works great but fails when i have multiple step
> > operations.
> >
> >  been introduced to Catalyst-Controller-FormBuilder-MultiForm and
> will
> > look at it.
> >
> > Any more recommendations to achieve the purpose below?
> >
> > step 1: generate a form prompting users to choose "loan" type (ie.
> home,
> > personal, corporate)
> > step 2: generate a form based on the type of loan chosen from step
> 2
> > step 3: save loan type to "loans" table (attributes from form in
> step
> > 1), get ID ,
> >           save the attributes from the form in step 2
> >
> > Using Html::FormFu,
> > in step 2, i have loaded the specific YAML config based on the loan
> type
> > by instantiating a new html::Formfu object.
> >
> > problem is, in step 3, by using $c->{stash}->{form}, i cannot get
> any
> > attributes found in step3.
> 
> I'm guessing that in step 3, your $c->stash->{form} is the one
> created
> by the FormConfig action - in which case it's the same form used for
> step 1.
> It won't validate the submitted parameters, because it doesn't know
> about any of the fields you generated in step 2.
> What you need to do is again generate the same form as step 2, and
> use
> that to validate the submitted parameters.
> Something like this:
> 
> 
> sub form1 : Path : FormConfig {
>     my ( $self, $c ) = @_;
> 
>     my $form = $self->stash->{form};
> 
>     if ( $form->submitted_and_valid ) {
>         $c->stash->{loan_type} = $form->param_value('loan_type');
> 
>         $c->detach('form2');
>     }
> }
> 
> sub form2 : Path : FormMethod('_build_form2') {
>     my ( $self, $c ) = @_;
> 
>     my $form = $self->stash->{form};
> 
>     if ( $form->submitted_and_valid ) {
>         # save to database
>     }
>     elsif ( $c->stash->{loan_type} ) {
>         # save loan-type value to hidden field
>         $form->get_field('load_type')->default(
> $c->stash->{loan_type} );
>     }
> }
> 
> sub _build_form2 {
>     my ( $self, $c ) = @_;
> 
>     # return hash-ref based on $c->req->params->{loan_type}
>     # automatically gets passed to $form->populate
> }
> 
> Although I haven't yet thought about how to handle auto-generated
> forms, there's also HTML-FormFu-MultiForm and the appropriate
> MultiForm* catalyst actions. These are all still in svn, but do
> work.
> 
> Carl
> 
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
> 
> 
> 





More information about the Catalyst mailing list