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.


In reply to Re: CGI::Application, have I made a big mistake. by Purdy
in thread CGI::Application, have I made a big mistake. by jdtoronto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.