Gossamer Forum
Home : Products : Links 2.0 : Customization :

add_error page error message

Quote Reply
add_error page error message
Hi All,

I have succesfulled added new fileds and everything is working fine except error reporting. What I mean by this is if a user fills in one of the new fields incorrectly, the add_error page is displayed, but no message to the user in terms of what they filled in incorrcetly, is displayed. Does anyone know how I can provide the user with the reason why the form was not accepted and what they need to change or add?

Thanks
Hamsterpants
Quote Reply
Re: [Hamsterpants] add_error page error message In reply to
You'll need to do some hacking in db_utils.pl, in "sub_validate_record." That's where you would add your field requirements and error statement. Not sure just what to do, maybe you can study it and figure it out...


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] add_error page error message In reply to
Hi Leonard,

Any chance you could give me some guidence as to what I need to change in the code below. I am new to cgi so not sure what I am looking for. for example, lets assume I added a new field called Keywords and it was a required field, how would I change the code below so that if it were left blank it would display and error message like "keywords is a required field"

sub validate_record {
# --------------------------------------------------------
# Verifies that the information passed through the form and stored
# in %in matches a valid record. It checks first to see that if
# we are adding, that a duplicate ID key does not exist. It then
# checks to see that fields specified as not null are indeed not null,
# finally it checks against the reg expression given in the database
# definition.
#
my ($col, @input_err, $errstr, $err, $line, @lines, @data);
my (%rec) = @_;

if ($rec{'add_record'}) { # don't need to worry about duplicate key if modifying
open (DB, "<$db_file_name") or &cgierr("error in validate_records. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB>) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
chomp;
@data = &split_decode($_);
($data[$db_key_pos] eq $rec{$db_key}) and return "duplicate key error";
}
close DB;
}
foreach $col (@db_cols) {
if ($rec{$col} =~ /^\s*$/) { # entry is null or only whitespace
($db_not_null{$col}) and # entry is not allowed to be null.
push(@input_err, "$col (Can not be left blank)"); # so let's add it as an error
}
else { # else entry is not null.
($db_valid_types{$col} && !($rec{$col} =~ /$db_valid_types{$col}/)) and
push(@input_err, "$col (Invalid format)"); # but has failed validation.
(length($rec{$col}) > $db_lengths{$col}) and
push (@input_err, "$col (Too long. Max length: $db_lengths{$col})");
if ($db_sort{$col} eq "date") {
push (@input_err, "$col (Invalid date format)") unless &date_to_unix($rec{$col});
}
}
}
if ($#input_err+1 > 0) { # since there are errors, let's build
foreach $err (@input_err) { # a string listing the errors
$errstr .= "<li>$err"; # and return it.
}
return "<ul>$errstr</ul>";
}
else {
return "ok"; # no errors, return ok.
}
}



Thanks once again
Hamsterpants
Quote Reply
Re: [Hamsterpants] add_error page error message In reply to
doesn't your add_error.html page contain the following?

<P><STRONG><%error%></STRONG></P>

if you look at the validate routine, it looks like it only detects 4 types of errors ( null for required fields, invalid format (???), invalid date, and too long. It does tell you the offending field.


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [esm] add_error page error message In reply to
You da man,

Cool

Must have deleted that when I edited add_error.html.....stuck it back in and all works great.



Thanks very much

Hamsterpants