Re: [Catalyst] Any recommendations for multiple forms in catalyst (have been using HTML::FormFu)?
On Tue, Jul 15, 2008 at 11:13:34PM +1000, [EMAIL PROTECTED] wrote: hi I was pretty successful in keeping things simple. sub create :Local :FormMethod('_get_dynamic_form') { my ($self, $c) = @_; # Set the template my $effective_template = 'listings/create.tt2'; $c-stash-{template} = $effective_template; my $loanType = lc($c-request-param('loanType')); my $step = $c-flash-{step}; $c-log-debug(Current operation: $step); if (defined($step) and $step =~ m/\w+/) { my $form_submission_success = $c-stash-{'form'}-submitted(); if ($form_submission_success) { if ($step eq 'first_step') { # now, set the next step. $c-flash-{'step'} = 'second_step'; } elsif ($step eq 'second_step') { # now, set the next step. $c-flash-{'step'} = 'third_step'; } elsif ($step eq 'third_step') { # now, we have acquired all data we need from steps one and two. # we do a redirect/forward/detach to save the values. Should go to 'sub save_complete_listing' $c-detach/ $c-res-forward/$c-redirect # all failed. } Have not been following that closely, but that looks complicated. I would do something like this with Form::Processor: sub first_step : Local { my ( $self, $c ) = @_; return $c-post_redirect( 'second_step' ) if $c-update_from_form; } sub second_step : Local { my ( $self, $c ) = @_; return $c-redirect( 'first_step' ) unless $c-session-{first_step}; return $c-post_redirect( 'third_step' ) if $c-update_from_form; } sub third_step : Local { my ( $self, $c ) = @_; return $c-redirect( 'second_step' ) unless $c-session-{second_step}; return $c-post_redirect( '/home', 'Thanks for your order' ) if $c-update_from_form: } My forms are classes, thus each form class knows to save their data in the session (except third_step which writes all the form data). They also know how to pre-populate the form from a previous submission (for example, if someone goes from form three back to form one. update_from_form() knows the form class from the action name, and $c-redirect and $c-post_redirect are simple short-cut methods to build the redirect and localize any messages that end up in flash. -- Bill Moseley [EMAIL PROTECTED] Sent from my iMutt ___ List: Catalyst@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/
Re: [Catalyst] Any recommendations for multiple forms in catalyst (have been using HTML::FormFu)?
2008/7/6 [EMAIL PROTECTED]: Nevertheless, I could only find Catalyst::Controller::FormBuilder::MultiForm. You mentioned there's HTML::FormFu::MultiForm. I have seen Catalyst::Controller::HTML::FormFu::Action::MultiForm but can't seem to read up on it cause there's no link to it in http://search.cpan.org/~cfranks/Catalyst-Controller-HTML-FormFu-0.03000/. Hi, The multiform module hasn't been released to cpan yet - you need to check it out from the subversion repository. You can find it, and the Cat-controller, in the 2 project folders: http://html-formfu.googlecode.com/svn/trunk/HTML-FormFu http://html-formfu.googlecode.com/svn/trunk/Catalyst-Controller-HTML-FormFu The reason it hasn't been released yet, is because the file upload handling needs a bit more work - other than that, it works fine, and I'm using it in a live application. Carl ___ List: Catalyst@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/
Re: [Catalyst] Any recommendations for multiple forms in catalyst(have been using HTML::FormFu)?
2008/7/6 Octavian Rasnita [EMAIL PROTECTED]: Will HTML::FormFu work under Windows? Yes! The reason I haven't released the MultiForm work to cpan yet, is because I've had trouble getting the tests to run under windows - but that's more an issue with how I was testing, rather than the actual code. Other than that though, I've got HTML-FormFu and all it's dependencies installed using VanillaPerl on WinXP. Carl ___ List: Catalyst@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/
Re: [Catalyst] Any recommendations for multiple forms in catalyst (have been using HTML::FormFu)?
2008/7/4 [EMAIL PROTECTED]: 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 ___ List: Catalyst@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/
Re: [Catalyst] Any recommendations for multiple forms in catalyst (have been using HTML::FormFu)?
2008/7/3 [EMAIL PROTECTED]: 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@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/
Re: [Catalyst] Any recommendations for multiple forms in catalyst (have been using HTML::FormFu)?
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 [EMAIL PROTECTED]: 2008/7/3 [EMAIL PROTECTED]: 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@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/ ___ List: Catalyst@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/
Re: [Catalyst] Any recommendations for multiple forms in catalyst (have been using HTML::FormFu)?
On 3 Jul 2008, at 09:05, Carl Franks wrote: 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. I'd disagree. At each step, you want to validate where you got so far, and if that validation goes well, move on - otherwise, move back... For non-trivial things such as this, I'd be looking at Class::Workflow, which does all of this and more, and you can persist your workflow state in DBIx::C... Cheers t0m ___ List: Catalyst@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/