Gossamer Forum
Home : Products : DBMan : Customization :

build select from second DB and carry over addition fields to autofill add form

Quote Reply
build select from second DB and carry over addition fields to autofill add form
I have searched until my head hurts, but I am sure it is somewhere! :)

I have a select field pulling in user.db that pulls from a second database called managers whith field 1 being the managers name. What I would like to do, is when the user selects their managers name, it will autofill the field MgrsEmail,(feild 2 from managers db)field 2, from the second database into their add form.

Any pointers where exactly to look for this type of solution? I am a cut and past DBman user pretty much.

Thanx in Advance.

John
Quote Reply
Re: [jlamphear] build select from second DB and carry over addition fields to autofill add form In reply to
This would require using a relational database. There's information about relational databases at http://www.jpdeni.com/.../Mods/relational.txt .

You could probably do what you want, using the instructions in that file. You would first need to define your "switch" subroutines. Then you would do something like:

&switch_to_managers;
&sub build_select_field_from_db(manager_name);
&switch_to_users;

A couple of things. First, the manager name would have to be the $db_key field in the managers database. Second, unless you use javascript, you can't populate the add form with the manager's email address. What you can do, though, is add the field in when you actually add the record to the database.

I would suggest that you make the manager's email address a hidden field on your form. Then, in sub add_record (in db.cgi), after

$status = &validate_record;

Add

Code:

if ($in{'db'} eq "user") {
&switch_to_managers;
my %rec = &get_record($in{'manager_name'));
&switch_to_users;
$in{'manager_email'} = $rec{'manager_email'};
}


If this works :-) you'd need to do something similar in sub modify_record.

Even though the field would be hidden on the form, you could have the field visible when the record is displayed.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.