|
View:
New views
14 Messages
—
Rating Filter:
Alert me
|
|
|
Any recommendations for multiple forms in catalyst (have been using HTML::FormFu)?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. Any ideas?? Also, any recommendations for multiple forms in catalyst? Thanks all _______________________________________________ List: Catalyst@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: Any recommendations for multiple forms in catalyst (have been using HTML::FormFu)?2008/7/3 <kakimoto@...>:
> > 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@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: 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 <fireartist@...>: > 2008/7/3 <kakimoto@...>: > > > > 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@... > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst > Searchable archive: > http://www.mail-archive.com/catalyst@.../ > Dev site: http://dev.catalyst.perl.org/ > > > _______________________________________________ List: Catalyst@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: 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@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: Any recommendations for multiple forms in catalyst (have been using HTML::FormFu)?2008/7/4 Tomas Doran <bobtfish@...>:
> > 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... I think there's been either a lacking in my explanation, or a lacking in your interpretation - if you follow my posted code, it does exactly what you describe. Display form 1 -> if valid goto form 2 -> if not valid redisplay form 1 Display form 2 -> if valid, use the data -> if not valid, redisplay form 2 This is exactly what HTML::FormFu::MultiForm does, but makes it more simple, as you can do it all within a single Catalyst action - it also encrypts previous form's data within a hidden field, so you don't need to revalidate earlier data. The bit I suspect the OP was getting wrong, was trying to validate form 2's submission, using form 1. However, rather than suggest a new module - to get the job done I suggested what I hoped would only be a minor code change (based on typical formfu usage, as the OP didn't give any code). Cheers, Carl _______________________________________________ List: Catalyst@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: Any recommendations for multiple forms in catalyst (have been using HTML::FormFu)?2008/7/4 <kakimoto@...>:
> 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@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: Any recommendations for multiple forms in catalyst (have been using HTML::FormFu)?Hi, carl, thanks for the help!! the doco you passed to me on was really good.. Thanks 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/. Yes, I know we could use perhaps another module to handle forms with multiple steps but I think HTML::FormFu is cool and would love to build my application with it. Would be great if you could shed some light here. thank you. Quoting Carl Franks <fireartist@...>: > 2008/7/4 Tomas Doran <bobtfish@...>: > > > > 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... > > I think there's been either a lacking in my explanation, or a > lacking > in your interpretation - if you follow my posted code, it does > exactly > what you describe. > > Display form 1 > -> if valid goto form 2 > -> if not valid redisplay form 1 > Display form 2 > -> if valid, use the data > -> if not valid, redisplay form 2 > > This is exactly what HTML::FormFu::MultiForm does, but makes it more > simple, as you can do it all within a single Catalyst action - it > also > encrypts previous form's data within a hidden field, so you don't > need > to revalidate earlier data. _______________________________________________ List: Catalyst@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: Any recommendations for multiple forms in catalyst (have been using HTML::FormFu)?2008/7/6 <kakimoto@...>:
> > 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@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: Any recommendations for multiple forms in catalyst(have been using HTML::FormFu)?From: "Carl Franks" <fireartist@...>
> 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 Will HTML::FormFu work under Windows? Octavian _______________________________________________ List: Catalyst@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: Any recommendations for multiple forms in catalyst(have been using HTML::FormFu)?2008/7/6 Octavian Rasnita <orasnita@...>:
> > 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@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: Any recommendations for multiple forms incatalyst(have been using HTML::FormFu)?From: "Carl Franks" <fireartist@...>
>> Will HTML::FormFu work under Windows? > > Yes! This is great! > 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 I have also installed it, but I needed to install DateTime and DateTime::Format::Strptime using ppm, because with cpan it gave some errors. Octavian _______________________________________________ List: Catalyst@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: Any recommendations for multiple forms incatalyst(have been using HTML::FormFu)?2008/7/6 Octavian Rasnita <orasnita@...>:
> > I have also installed it, but I needed to install DateTime and > DateTime::Format::Strptime using ppm, because with cpan it gave some errors. Okay, when I get the time, I'll try installing on a fresh perl install, and see what happens. I can remember hitting some missing prereq-dependency recently, but can't find any relevant RT bugs on any of the DateTime* modules we use - my bad for not following it up at the time! Carl _______________________________________________ List: Catalyst@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: Any recommendations for multiple forms in catalyst (have been using HTML::FormFu)?hi
I was pretty successful in keeping things simple. I figured I d' keep all steps that needed a form to be generated (ie for data entry) to "sub create". Then, at the very end when I am done getting all the data (from forms shown on the webpage), I would then redirect/forward/detach to another method, "sub save_complete_listing". 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. } A few questions: 1) What is the difference between Detach, forward and redirect?? I read through the docos and they are under explained. Refered to http://search.cpan.org/~mramberg/Catalyst-Runtime-5.7014/lib/Catalyst.pm#___top Correct me if i am wrong: a) $c->forward - control will be passed to whatever target it is defined with. Once the target is finished with execution, control will go back to where it was "forwarded" from b) $c->detach - same as forward BUT control does not go back to where it was "detached" from. c) $c->res->redirect - someone please give me an idea cause my initial thoughts was that it should resemble forward 2. When we do a $c->forward/$c->detach/$c->res->redirect, would a) $c still be defined?? b) $c->stash contents still be defined?? c) $c->flash contents still be defined?? For stash and flash, I noticed they got wiped off. Particularly, $c->stash/flash->{'form'}. To be extra safe, before the $c->forward/$c->detach/$c->res->redirect, I even explicitly did a "$c->flash->{'form'} = $c->stash->{'form'}" and yet the values have dissappeared. Please help. Thanks _______________________________________________ List: Catalyst@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: Any recommendations for multiple forms in catalyst (have been using HTML::FormFu)?On Tue, Jul 15, 2008 at 11:13:34PM +1000, kakimoto@... 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 moseley@... Sent from my iMutt _______________________________________________ List: Catalyst@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
| Free Forum Powered by Nabble | Forum Help |