Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: CGI::Application, have I made a big mistake.

by Purdy (Hermit)
on Nov 25, 2003 at 14:55 UTC ( #309915=note: print w/replies, xml ) Need Help??


in reply to CGI::Application, have I made a big mistake.

I haven't seen anyone point you in the direction of CGI::Application::ValidateRM yet - that's what I've been using recently and it works great!

The way I look at it, I have separate run_mode's for every "page" or step in the application. Then (following your example), when mode_001 is processed/submitted, it goes to mode_002 (instead of back to mode_001) and in mode_002's run_mode method, I use ValidateRM's check_rm method, which will take care of your error handling for you and you can tell it which run_mode to return to, if there was an error.

sub mode_001 { my ( $self, $errs ) = @_; # ... $template->param( $errs ) if $errs; $template->output; } sub mode_002 { my ( $self, $results, $err_page ); $self = shift; ( $results, $err_page ) = $self->check_rm( 'mode_001', '_mode001_profile' ); return $err_page if $err_page; # If you've gotten this far, all the data is ok per # your FormValidator object } sub _mode001_profile { return { 'required' => [ qw( email password1 password2 ) ], 'constraints' => { 'email' => sub { return Email::Valid->address( shift ) +; } }, 'msgs' => { 'any_errors' => 'some_errors', 'prefix' => 'err_', }, }; }

Hope that helps!

Peace,

Jason

Update: It will also prefill out the previous form with the user's data when/if it returns to a previous run_mode. So if they provided their first e-mail address, but not any other stuff, then it will represent the original form with the data that the user did specify along with those 'msgs' (i.e. err_password1, err_password2) that you can incorporate into your template to color things red or whatever.

Replies are listed 'Best First'.
Re: Re: CGI::Application, have I made a big mistake.
by freddo411 (Chaplain) on Nov 25, 2003 at 18:22 UTC
    Great post, ++ to parent.

    I to use ValidateRM with great success. The use use of VRM 'encouraged' me to keep each rm to just a single presentation screen, because when using VRM to process a form submission you call the orginal form presentation run mode to (re)produce the screen with errors message and data overlaid. This works best if the orginal run mode simply does presentation.

    I'd like to add one useful tip. VRM requires HTML::FillInForm to repopulate the info into the presenation form. This is a very handy module for prefilling out a form in your run mode, if, for example you are doing a edit operation on something you already have in the database. A code example of filling out into a template file:

    ... code to setup my $t template, and get info from the database into %fdat would be here ... my $html = $t->output; if ( %fdat ) { my $fif = new HTML::FillInForm; $html = $fif->fill(scalarref => \$html, fdat => \%fdat ); } return $html; # this is the filled-out HTML file

    -------------------------------------
    Nothing is too wonderful to be true
    -- Michael Faraday

Re: Re: CGI::Application, have I made a big mistake.
by jdtoronto (Prior) on Nov 25, 2003 at 15:37 UTC
    Thank you,

    I had printed out the docs and have them in front of me but hadn't really looked at them. TIme to do some more reading I think, before the project gets too far along and I can't change things.

    [jdtoronto}

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://309915]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2019-11-22 05:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (108 votes). Check out past polls.

    Notices?