Good morning.

Yesterday I posted my confusion with dispatch issues while using CGI::App and CGI::FormBuilder. The code below is a runnable sample, I've written in parrallel, largely by copying / adapting from perldoc, to the nearly complete script that's waiting for me to figure this piece out.

This script only seems to dispatch to pages with required fields in their forms. Otherwise it jumps straight from registrant_form (where it collects a name and state) to payment form (where it collects credit card). And when I make a field required on a page's form, it only stops on that form due to a validation error, not as if on its first pass through.

Here is the 8 line cgi script that uses the module:

#!/usr/bin/perl -wT use strict; use lib qw{/path/to/sandbox/Registration/Registration/t/}; use dispatch_test; my $dispatch = dispatch_test->new(); $dispatch->run(); 1;
And here is the 130 or so line test module:

package dispatch_test; use strict; use warnings; use diagnostics; use CGI::Carp qw/fatalsToBrowser/; use base 'CGI::Application'; use CGI::FormBuilder; use CGI; use Data::Dumper; 1; sub setup { my $self = shift; # my $rm = $form->cgi_param('rm'); $self->start_mode('RegForm'); $self->mode_param('rm'); $self->run_modes( 'RegForm' => 'registrant_form', 'RegistrantNeeds' => 'registrant_needs', 'Checkout' => 'checkout', 'Payment' => 'payment', 'Thankyou' => 'thank_you', 'Admin' => 'admin_screen', ); } sub registrant_form { my $self = shift; print STDERR "dispatch_test: Now running registrant_form().\n"; my $output = ""; my $q = new CGI; my $rm = $q->param('rm') || 'RegForm'; my $form = CGI::FormBuilder->new( fields => [qw/fname lname state/], required => [qw/fname lname state/], params => $q, # params from CGI.pm keepextras => 1, # keep mode param submit => [qw/Proceed_to_Meals/], ); if($form->submitted && $form->validate){ $rm = 'RegistrantNeeds'; # $output = $form->confirm(header => 1); return $self->registrant_needs(); } else { $output = $form->render(); } print STDERR "dispatch_test->registrant_form() says \$rm is $rm.\n"; return $output; } sub registrant_needs { my $self = shift; print STDERR "dispatch_test: Now running ->registrant_needs().\n"; my $output = ""; my $q = new CGI; my $rm = $q->param('rm') || 'RegistrantNeeds'; my $form = CGI::FormBuilder->new( fields => [qw/housing meals other/], required => [qw/meals/], params => $q, # params from CGI.pm keepextras => 1, # keep mode param submit => [qw/Proceed_to_Checkout/], ); if($form->submitted && $form->validate){ $rm = 'Checkout'; return $self->checkout(); } else { $output = $form->render(); } return $output; } sub checkout { my $self = shift; print STDERR "dispatch_test: Now running ->checkout().\n"; my $output = ""; my $q = new CGI; my $rm = $q->param('rm') || 'Checkout'; my $form = CGI::FormBuilder->new( fields => [qw/donation/], required => [qw/donation/], params => $q, # params from CGI.pm keepextras => 1, # keep mode param submit => [qw/Proceed_to_Payment/], ); if($form->submitted && $form->validate){ $rm = 'Payment'; return $self->payment(); } else { $output = $form->render(); } return $output; } sub payment { my $self = shift; print STDERR "dispatch_test: Now running ->payment().\n"; my $output = ""; my $q = new CGI; my $rm = $q->param('rm') || 'Payment'; my $form = CGI::FormBuilder->new( fields => [qw/creditcard/], required => [qw/creditcard/], params => $q, # params from CGI.pm keepextras => 1, # keep mode param ); if($form->submitted && $form->validate){ $rm = 'Thankyou'; return $self->thank_you(); } else { $output = $form->render(); } return $output; } sub thank_you { return "Thanks for your registration.<br>We look forward to seeing y +ou."; }
This is only my second attempt to put CGI::FormBuilder and CGI::Application together on a project. Apparently there is something I am missing in this equation. Any insight, direction, working sample code, etc., etc., would be appreciated. Thank you.

-- Hugh

if( $lal && $lol ) { $life++; }

In reply to seeking further clarity on dispatch logic w/ CGI::Application & FormBuilder by hesco

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.