Monks

I'm writing a form to be updated and the results put into the DB. Generally, it works, but if the DB update fails (or some other code at that point) I'd like to re-display the form, along with a msg. Ideally I'd like to be able to display the msg next to a specific field (if related).
An example code flow from the docs http://www.formbuilder.org/download/CGI-FormBuilder-3.0501/docs/CGI/FormBuilder.html looks like this:

# Check to see if we're submitted and valid if ($form->submitted && $form->validate) { # Get form fields as hashref my $field = $form->fields; # Do something to update your data (you would write this) do_data_update($field->{lname}, $field->{fname}, $field->{email}, $field->{phone}, $field->{gender}); # Show confirmation screen print $form->confirm(header => 1); } else { # Print out the form print $form->render(header => 1); }
However it doesn't handle the situation I described above. I tried to force a data validation error to occur if my own error flag is set, and even activated the debug option, but I don't get any msg on screen and no debug output appears anywhere I can see.
# Check form if( $form->submitted ) { if( $form->validate ) { # More data munging $fields = $form->field; %tidy_fields = do_data_tidy($param_action, %{$fields}); # Amend Database $cfg::err_flag = 0; db_start_txn() if( !$cfg::err_flag ); update_database(%tidy_fields) if( !$cfg::err_flag ); db_commit_txn() if( !$cfg::err_flag ); if( !$cfg::err_flag ) { print $form->confirm(sticky => 1,header => 1); } else { #DEBUG log_msg("mytrap"); # Invalid; show form and allow corrections $cfg::err_flag = 0; $form->field(name => 'new_status', message => "Uknown change requested" ); $form->validate(new_status => 'NONE'); print $form->render(sticky => 1, debug =>2); } } else ....
FYI, I (very) rarely do CGI of any type and I've never used CGI::FormBuilder before, so please answer in simple terms.

Thx
Chris


In reply to CGI::FormBuilder & custom msgs by chrism01

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.