Gossamer Forum
Home : Products : DBMan : Installation :

ALLOWING BLANK DATES

Quote Reply
ALLOWING BLANK DATES
I'm new to Perl/CGI and I thought maybe I could get a jump-start on figuring this out. The not_null flag does not seem to work with date fields. Any suggestions? Also, I noticed that 1900 is being added to the $year. Is this stuff Y2K compliant?
Quote Reply
Re: ALLOWING BLANK DATES In reply to
You can fix the "not_null" date problem by replacing sub validate_record (in the db.cgi file) with the following. (It only requires that you move a few lines. Those lines are in bold print below. I also took out the comment lines to save space. You should leave them in your script, though.)

Code:
sub validate_record {
# --------------------------------------------------------

my ($col, @input_err, $errstr, $err, $line, @lines, @data);

if ($in{'add_record'}) {
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;
$line = $_; chomp ($line);
@data = &split_decode($line);
if ($data[$db_key_pos] eq $in{$db_key}) {
return "duplicate key error";
}
}
close DB;
}
foreach $col (@db_cols) {
if ($in{$col} =~ /^\s*$/) {
($db_not_null{$col}) and
push(@input_err, "$col (Can not be left blank)");
}
else {
($db_valid_types{$col} && !($in{$col} =~ /$db_valid_types{$col}/)) and
push(@input_err, "$col (Invalid format)");
(length($in{$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($in{$col});
}

}
}

if ($#input_err+1 > 0) {
foreach $err (@input_err) {
$errstr .= "<li>$err";
}
return "<ul>$errstr</ul>";
}
else {
return "ok";
}
}

Quote:
Also, I noticed that 1900 is being added to the $year. Is this stuff Y2K compliant?

Yes. The year value that is return by "localtime" is the number of years since 1900. Right now, the value is 99. Next year the value will be 100.

Some other scripts you might see (older ones) might have the year defined as "19".$year. That will give a really odd result next year when it will be "19100."

------------------
JPD







[This message has been edited by JPDeni (edited May 14, 1999).]