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:
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 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); }
FYI, I (very) rarely do CGI of any type and I've never used CGI::FormBuilder before, so please answer in simple terms.# 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 ....
Thx
Chris
In reply to CGI::FormBuilder & custom msgs by chrism01
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |