hesco has asked for the wisdom of the Perl Monks concerning the following question:

Hello.

I have a five form application being coded with CGI::Application and CGI::FormBuilder. @clients want delivery by tomorrow morning. After successfully dispatching from form1 to form2 to form3, I got stuck on attempts to dispatch to form4. Instead, it cycles back continuously to form2. (Even before @clients eliminated form1).

That was the first week. The second week was spent coding completely around that issue. Now practically eveything is in place, EXCEPT the dispatch from form3 to form4.

My form definitions include:

my $form = CGI::FormBuilder->new( ... ... ... keepextras => 1, ... ... ...
My dispatch logic looks like this:

my $output = ''; if ($form->submitted && $form->validate) { print STDERR "Confirm Registrant Needs Data. Store in db.\n"; print STDERR "->registrant_needs() about to invoke ->insert_reg_ne +eds_form().\n"; my $fields = $form->fields; $self->insert_reg_needs_form($dbh,$reg_id,$fields); $rm = "Checkout"; print STDERR "->registrant_needs() says about to dispatch to ->che +ckout().\n"; return $self->checkout($dbh,$reg_id); } else { print STDERR "Render Registrant Needs Form again.\n"; $output .= htmlgui::return_remote_header_as_string(@template_field +s); $output .= $self->config_param('RegistrantNeeds.pre_form_copy'); $output .= $form->render(); $output .= $self->config_param('RegistrantNeeds.post_form_copy'); $output .= $self->credits(); $output .= htmlgui::return_remote_footer_as_string(@template_field +s); $rm = "RegistrantNeeds"; print STDERR "->registrant_needs() says: about to render registran +t_needs form.\n"; } print STDERR "Script is ready to render: \n\n$output \n\n"; return $output;
So here is what is baffling me. Although from a gui browser, I watch it render the RegistrantNeeds form (form3), and cycle back to it (after resubmitting form2) with sticky data, I do not see my STDERR debug messages in my apache error log. I see no validation error messages and I see no evidence of having been dispatched with "return self->checkout($dbh,$reg_id);". There is no other code in the application which would render this form.

Any clues to help move me along would be greatly appreciated.

-- Hugh

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

Replies are listed 'Best First'.
Re: Confused by Dispatch Issues w/ CGI::App and CGI::FormBuilder
by samtregar (Abbot) on May 18, 2006 at 16:19 UTC
    Are you sure you're using CGI::Application? Eliminating twisty if/else logic like this is exactly what CGI::App was built to avoid!

    But back to the issue at hand - are you sure you're editing the right script and the right place in it? Try putting a die() in the code path you think is running. Does the app die? If it doesn't, are you running in Apache::Registry or as a mod_perl handler? You might need to restart the server.

    Ultimately you may need to use the debugger if you can't guess enough to put confessional prints in the right place. Give that a try if you're out of ideas - sometimes there's no substitute for seeing what your code is really doing.

    -sam

Re: Confused by Dispatch Issues w/ CGI::App and CGI::FormBuilder
by hesco (Deacon) on May 18, 2006 at 17:47 UTC
    Sam: Thanks for the reply. Apache configuration says that I am looking at the right script and monitoring the right log. Though apache has been performing rather strangly of late, dieing unexpectantly. If there is some easier way to make these forms dispatch using CGI::App, I'd surely like to hear about it. Because despite my hopes, simply defining $output and $rm has not been sufficient to the cause in my very limited experience with these tools. -- Hugh
    if( $lal && $lol ) { $life++; }
      Serriously - put the die() in. Just looking at the Apache conf isn't enough to prove you're editing the right script AND the right part of the code. This simple technique has saved me loads of time!

      -sam

Re: Confused by Dispatch Issues w/ CGI::App and CGI::FormBuilder
by hesco (Deacon) on May 18, 2006 at 20:08 UTC
    Sam:

    Sorry, I did add some die statments. When those die statements are in the registrant_needs() routine, but outside the dispatch conditional, they are printed to the browser with a little help from Carp. When I move them inside the blocks of the conditions, either it works in the else clause, or it doesn't work in the if clause. Without the die; the if clause merely returns control to form2, instead of passing it on to form4. With it, the browser hangs w/o rendering the message fed to die();. Also, I'm not seeing my debug messages in the log. Its all very perplexing.

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