Gossamer Forum
Home : Products : DBMan : Customization :

Help with passing values please?

Quote Reply
Help with passing values please?
I thought I had done this right, but obviously I didnt and not sure where to go from here.

This is the code I had:
Code:
if ($per_admin) { print qq|
<TR><TD width="250"><$font_color>Member:</FONT></TD><TD align="right">&nbsp;<INPUT TYPE="TEXT" NAME="Member" SIZE="11" VALUE="$per_mem" MAXLENGTH="11"></TD></TR> |;
}
else { print qq| <input type="hidden" NAME="Member" VALUE="$per_mem">|; }

which what I was trying to do is say if logged in as admin (or have admin permission), view the Member field and pass the value of per_mem into that field, if not admin, make the Member field hidden, but still pass the value of per_mem. Then I am trying to sort by the Member field for 1's to be first and 0's to be second so since I have a relational db, I changed this line: $db_sort{'Member'} = 'numer';

So I logged in as admin and added a record. Then I logged in as another user with a per_mem permission of 0 and added a record, but when I logged back in again as admin to test it, the record from the user with per_mem of 0 showed up as 1. I checked it out in my default.pass file and per_mem shows up as 0 still, but maybe because I logged in as admin it set the value of the Member field to 1 instead of the correct value of 0??
This is where I'm confused. I figured I could just input the value of per_mem into the 'Member' field instead of making the record form say $rec{'Member'} because then I believe that would take alot more work trying to figure out how to pass per_mem into the 'Member' field, but maybe that needs to be done?? Crazy
So can anyone assist me with the correct code to use to accomplish this? Thanks!
Quote Reply
Re: [wdu2002] Help with passing values please? In reply to
Quote:
So I logged in as admin and added a record. Then I logged in as another user with a per_mem permission of 0 and added a record, but when I logged back in again as admin to test it, the record from the user with per_mem of 0 showed up as 1. I checked it out in my default.pass file and per_mem shows up as 0 still, but maybe because I logged in as admin it set the value of the Member field to 1 instead of the correct value of 0??

Yes, I think the when you logged in as admin it set per_mem to 1 as since that is the value of the currently logged-on user and not the value coming from the record.

It would seem that it admin wants to view a users record and the value of the user's per_mem, then the value of per_mem would need to be written to the record when the user creates the record.

I think you were on the right track, except for in the

if ($per_admin) { print qq|

the VALUE="$per_mem" would be VALUE="$rec{'Member'}"

When the user creates the record (in the add or modify sections) that is where you would need the

print qq| <input type="hidden" NAME="Member" VALUE="$per_mem">|;

Hope thet helps.


Joe
Quote Reply
Re: [joematt] Help with passing values please? In reply to
Hi Joe;

Thanks for replying. That code that I had above is in my html_record_form sub which is the sub that is used to add a record, so it should put the value of per_mem into the record when a new one is added. I'm not sure if the value is being changed when the record is added or after I relogin as admin to check....but I need the field to be hidden for everyone else other than admin, so Im not sure how to go about inputting the correct value no matter who is logged in. The whole purpose of this field is to sort by putting records with member value of 1 first before the member value of 0. But maybe there is another way?
Quote Reply
Re: [wdu2002] Help with passing values please? In reply to
I think you are correct to put that code into html_record_form to get the value into the record.

If you want to hide the value from non-admin users you will need a similar statement in html_record, as that is used for viewing.

In html_record, if ($per_admin) VALUE="$rec{'Member'}"

and not VALUE="$per_mem"

For html_record_form, as you had it the first time I think is correct (unless you are using the modify record to check the value of the record, can you check it with view_record instead?).

If you must use modify_record to check the value, then you would need something to check to see if the current user (admin) is the same as the user who created the record.

For me, to check that the correct value of per_mem is added correctly, I would just view the database flatfile.

Joe
Quote Reply
Re: [joematt] Help with passing values please? In reply to
Ok, I *think* I have it passing the correct values now. For the users with a per_mem value of 1 it puts 1 into the Member field, but with users with a per_mem value of 0, it just leaves the Member field blank. Is that ok?

If that is ok, can you help with the sorting? Because that isnt working. I have a relational db, so in my db.cgi, I have this under my default db:

$db_sort{'Member'} = 'numer';

Is that right or wrong? It isnt sorting by 1's being first, just in order they were added, so I'm not sure if I need to add something somewhere else. Thanks for any help! Smile
Quote Reply
Re: [wdu2002] Help with passing values please? In reply to
Regarding Member field is blank for per_mem = 0, I think it will be OK, but you could add another if statement so that it gets set for certain;

elsif ($per_mem) { print qq| <input type="hidden" NAME="Member" VALUE="$per_mem">|; }

else { print qq| <input type="hidden" NAME="Member" VALUE=0>|; }

Regarding the sorting, you would also need to set a sort order, as 0 or blank would come before 1's. (you prob knew that).

I am just guessing that
$db_sort{'Member'} = 'numer';
is setting the default sort and I am just guessing again that = 'numer' is not needed, as perl will determine the type of sort required based on the data, except when it is a date.

Are you calling the results from a static link or are the users submitting a search and you just want to control the default sort order? In either case I think you need to pass alone the
&sb= column number
&so=descend

Just add these to the static link or make them hidden fields in the search form.

I hope Paul comes alone and corrects me if I am guessing wrong.

Last edited by:

joematt: Mar 7, 2003, 9:41 AM
Quote Reply
Re: [joematt] Help with passing values please? In reply to
Thanks Joe, that helped me understand better. I have added the hidden sort by and sort order to my search form and my static links for my main page, but unfortunately I get an error that something in db.cgi needs to be changed, but Im not sure what. The error I get is:

Error Message : fatal error: Not a CODE reference in sort at db.cgi line 725.


This is line 725 of my db.cgi file:

Code:
foreach $hit (sort $sort_func (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit; $last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sortedhits, @hits[$first .. $last]);
}
@hits = @sortedhits;
}

Im pretty familiar with html.pl, but not so much so with db.cgi so can you or anyone else help me with what needs to be changed in this part? Thanks!
Quote Reply
Re: [wdu2002] Help with passing values please? In reply to
I can't see the problem based on the code you posted, mostly as I am not so well versed in Perl. If you are still stuck, consider posting or PM me the link string or an address were I can make a search, then I can try some different searches/links to see if I can find one that works.

Hope you had a nice weekend.