Gossamer Forum
Home : Products : DBMan : Customization :

if userid then

Quote Reply
if userid then
Hi Guys,
Can someone plleeease help me with the following:
I am trying to setup defaults for individual users for sub_add_form only. In other words if userid = joe and he wishes to add the add_form contains his default Tel and Email. User george will obviously have different values. I tried:

if ($db_userid = "joe") {
$rec{'Tel'} = "375 6230";
$rec{'Fax'} = "375 6450";
$rec{'Email'} = "joe\@server.com";
}
if ($db_userid = "george") {
$rec{'Tel') = "899-0128";
$rec{'Fax'} = "899-0151";
$rec{'Email'} = "george\@server.com";
}
else {
&html_add_failure
}

at the start of sub_add_form, but I always end up with the last if statements block values. I am sure this has been a common question, but I cannot find anything on previous postings. Any help would be greatly appreciated.

Many thnaks in advance.
Greg
Quote Reply
Re: if userid then In reply to
Two things.

First, use eq instead of =. Second, for all the "middle" options, use elsif instead of else.

Code:
if ($db_userid eq "joe") {
$rec{'Tel'} = "375 6230";
$rec{'Fax'} = "375 6450";
$rec{'Email'} = "joe\@server.com";
}
elsif ($db_userid eq "george") {
$rec{'Tel') = "899-0128";
$rec{'Fax'} = "899-0151";
$rec{'Email'} = "george\@server.com";
}
else {
&html_add_failure
}

(I forget the eq thing all the time! Smile )


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





Quote Reply
Re: if userid then In reply to
Hello Carol,

A pleasure to hear from you Smile.

I am pulling my hair out with this one. I have tried the = and eq, but I just cannot seem to get this damn thing to work. All I want to do is set some basic defaults based on the userid. I am putting this elaborate if then statement at the start of html_add_form, but I get zip when I add, just bank fields. Where can I insert this if then to make it fill in the basic fields?

Your assistance would be greatly appreciated.
Greg
Quote Reply
Re: if userid then In reply to
You'll have to do a little work in sub html_add_form to do this.

Before you have your "if" statments, add

Code:
%rec = &get_defaults;

Then put in the "if" statements.

Then change

Code:
&html_record_form (&get_defaults);

to

Code:
&html_record_form (%rec);

The problem is that the %rec hash is being overwritten by the defaults. Get the defaults first, then put in your "if"s and then send the whole thing to the form.


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





Quote Reply
Re: if userid then In reply to
Make sure that $db_userid is getting passed. Click on View or Add and check the URL for &db_userid=something. If it isn't there, you won't be able to compare against it. The easiest way to test it to add something like
Code:
db_userid = $db_userid
to the end of the html formatting in sub html_record in html.pl. Add or View a record to get the results page and see if a value is getting through. $db_uid also contains the username, but with some added digits. I had to do a substring of $db_uid to chop down to the user ID. I'm sure JPD could quickly tell you how to add $db_userid to the URL if it is not getting passed.

KipT
Quote Reply
Re: if userid then In reply to
Carol you are a life saver Smile.

Thanks a ton
Greg