Gossamer Forum
Home : General : Perl Programming :

one form two functions

Quote Reply
one form two functions
Hi,

I need to set up one form which will query two databases and I've been able to do it with javascript without a problem...but I'd prefer to use a perl script, that way there's no issues like, old browsers or people that disable javascript...you get the idea. Anyway, would anyone be interested in lending a hand? Thanks.

Quote Reply
Re: one form two functions In reply to
Oh, to clarify, I don't need to query both databases at the same time, it's either one or the other. Thanks.

Quote Reply
Re: one form two functions In reply to
Are these databases local or on another site?

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: one form two functions In reply to
MySQL/flatfile?

Installs:http://wiredon.net/gt
FAQ:http://www.perlmad.com

Quote Reply
Re: one form two functions In reply to
Whether they are local or remote is not really important.

Installs:http://wiredon.net/gt
FAQ:http://www.perlmad.com

Quote Reply
Re: one form two functions In reply to
Hey Guys,

Actually there local and both are flat files. After hours of trying to come up with something that works myself and digging and searching I actually found a pre-made script. Here's the deal though. It works fine with a few exceptions. I'm testing both methods and here's where I'm at with this.

Javascript Method

Pros
- It seems to process faster.
- I don't have to pre-define variables (user can choose/select).
- Doesn't use the servers resources (I think I read that somewhere at least??)

Cons
- It's not browser platform friendly
- User may have javascript turned off
- Values and Field names have to be identical between the two databases if allowing user to select options
- Did I mention that it's not browser platform friendly?

Cgi Method
Pros
- Will work with all browsers/users. (Although I noticed in the script, it says if it's called by using the "Post" method, it uses javascript anyway!)
- Can specify different (only pre-determined) values to pass to each query. Now that I think about it, this might be listed under Cons also because it's flexible in the respect that you can specify different values (IE: boolean=and/or, Case=sensitive/insensitive, etc.) for each different script you direct to, but they have to be pre-determined in the config section...meaning the user can't choose.

Cons
- Uses more server resources (once again....I'm guessing??)
- After looking at...(I'll post the url to the script here in a second) I would have no idea how to modify/add the option to make it so the user can select aditional options (boolean=and/or, Case=sensitive/insensitive, etc), in addition to which database to search! You'll see what I mean if you look at it--- there's a bunch of $I1IIIIII1III111I in the code, which I have no idea what it's used for.

So basically, I'd like to hear your guy's comments or suggestions. Or if you have a better/more customizable script in mind, that would be great too. Anyway, for anyone else in need of something like this the script can be found here: http://www.anaconda.net, and it's called Director. If anyone else wants the javascript version that I'm testing I can post that here also. Ok, I think that about covers it. I know this isn't a big deal, but I just want to do it right the first time. Thanks again.
Quote Reply
Re: one form two functions In reply to
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
Quote Reply
Re: one form two functions In reply to
Well, I guess I needed to crash out for a couple hours! I decided to dump that anaconda one and fix the one I was working on. I finally got it going...whew! Now I can allow the user to select as many options as needed (although I only needed two). Thanks for that thorough post Eliot...it got me thinking about some other stuff too. Well, thanks again for the help...I appreciate it.