One suggestion...use multiple pages....
Page 1: Select Database Basically, a matter of adding conditional statements and calling the appropriate subroutine within the script.
EXAMPLE:
Code:
if ($in{'db'} eq "database1") {
&adddata1;
}
elsif ($in{'db'} eq "database2") {
&adddata2;
}
else {
&displayform;
} And in the form, simply use RADIO buttons for selecting the appropriate database:
Code:
<input type="radio" name="db" value="database1"> Database1
<input type="radio" name="db" value="database2"> Database2 (of course, change the
$in to whatever parsing codes you are using...best to use
CGI.pm and use something like
$in->param('db'))
Page 2: Input data into Selected Database Basically create additional subroutines and use specific databases in these subs.
And, you're absolutely correct about the PROS/CONS...I always use a mixture of client and server error checking codes...mostly server-based due to the possibility of end-users turning off javascript.
-OR-
If you want to use ONE form, use the same radio select buttons...but use one subroutine with conditional statements.
EXAMPLE:
Code:
my $db_name1 = "/absolute/path/to/database1.db";
my $db_name2 = "/absolute/path/to/database2.db";
my $delim = '|';
if ($in{'db'} eq "database1") {
(-e $db_name1) ?
open (DATA,">>$db_name1") :
open (DATA,">$db_name1");
}
if ($in{'db'} eq "database2") {
(-e $db_name2) ?
open (DATA,">>$db_name2") :
open (DATA,">$db_name2");
}
$data = "$in{'fieldname1'}$delim$in{'fieldname2'}\n";
print DATA $data;
close(DATA) Of course, if you want end-users to be able to add data in both databases, use checkboxes...
For SEARCHING databases, all you have to do is use redirection codes (Location:) or OPEN the appropriate database file.
BTW: Codes have been provided before for doing this in this forum and also in the
Links 2.0 Customization Forum and in the
Resources section.
Regards,
Eliot Lee