Gossamer Forum
Home : Products : DBMan : Customization :

search options, dropdown list

(Page 2 of 2)
> >
Quote Reply
Re: search options, dropdown list In reply to
hello again,

Is it possible to have the above script for add and modify records?
Because now people can add/modify a city what they like...mmmmhh

greetings,
[removed by request]
The Netherlands (Europe)

Quote Reply
Re: search options, dropdown list In reply to
Yes, you could do that.

Replace sub validate_record with the following:

Code:

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);

if ($in{'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;
$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*$/) { # 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} && !($in{$col} =~ /$db_valid_types{$col}/)) and
push(@input_err, "$col (Invalid format)"); # but has failed validation.
}
(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 ($in{'City'}) {
$city_start = lc(substr($in{'City'},0,1));
if ($city_start eq 'x') {
$in{'City'} = '';
}
else {
open (CITY, "$db_script_path/$city_start.txt") or
&cgierr("error in view_failure. unable to open city file: $db_script_path/$city_start.txt.\nReason: $!");
@cities = <CITY>;
close CITY;
foreach $city (@cities) {
chomp $city;
if (lc($city) eq lc($in{'City'})) {
$city_found = 1;
last;
}
}
unless ($city_found) {
$in{'City'} = '';
push (@input_err, qq|The city name you entered was incorrect. Choose the city from the list below or
use the "Back" button on your browser to go back to the previous form.|);
$city_select = qq|<SELECT name="City">|;
foreach $city (@cities) {
$city_select .="<option>$city\n";
}
$city_select .= "</select>";
}
}
}

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.
}
}

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: search options, dropdown list In reply to
thank you,thank you,thank you,thank you very muchSmile
This is great !

greetings,
[removed by request]
The Netherlands (Europe)

Quote Reply
Re: search options, dropdown list In reply to
You're welcome. Smile (I wasn't sure it would work!! Wink)


JPD
http://www.jpdeni.com/dbman/
> >