Gossamer Forum
Home : Products : DBMan : Customization :

Recording uid without extra characters

Quote Reply
Recording uid without extra characters
I am using a Userid field, but I do not want it to appear to users (only admins) ... yet I need the field to be filled with the user's ID that they logged in with.



When I use the $db_uid or whatever, the user ID is filled in, but with .102910239 or some sort of security key such as that.



Is there a way to strip that number and stuff out so that just the user ID is recorded?
Quote Reply
Re: [astroboy5714] Recording uid without extra characters In reply to
The userid is the field which designates who owns the record.

When you use $db_uid is also contains the logged in user's authentication. This is used in links and is a part of $db_script_link_url when a user is logged. This maintains their login status and displays menu options according to their permissions.

You can just make your Userid a hidden field in your html_record_form. Or add it under a section for admin only such as:

|;
if ($per_admin) { print qq|
<TR><TD><$font>User ID: </font></TD><TD><$font><input type="TEXT" NAME="Userid" VALUE="$rec{'Userid'}"></TD></TR>|;
}
else {
print qq| <TR><TD colspan=2><input type="hidden" NAME="Userid" VALUE="$rec{'Userid'}"></TD></TR> |;
}
print qq|

How can I get the userid to be displayed in the add form?

In db.cgi, sub get_defaults, after:

foreach $field (keys %db_defaults) {
$default{$field} = $db_defaults{$field};

add:

####### add userid in add form #####
($auth_user_field >=0) and ($db_defaults{$db_cols[$auth_user_field]} = $db_userid);
####### end change #######

If you don't want the userid automatically filled in if you are logged in as admin use the following instead:

####### add userid in add form unless admin ###
unless ($per_admin) {
($auth_user_field >=0) and ($db_defaults{$db_cols[$auth_user_field]} = $db_userid);
}
####### end change #######

This and many other tips and trick can be found in the FAQ noted below.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/

Last edited by:

LoisC: Feb 3, 2002, 6:20 PM
Quote Reply
Re: [LoisC] Recording uid without extra characters In reply to
>>
|;
if ($per_admin) { print qq|
<TR><TD><$font>User ID: </font></TD><TD><$font><input type="TEXT" NAME="Userid" VALUE="$rec{'Userid'}">
}
<<

|;
if ($per_admin) {
print qq| <TR><TD><$font>User ID: </font></TD><TD><$font><input type="TEXT" NAME="Userid" VALUE="$rec{'Userid'}">|;
}

Last edited by:

RedRum: Feb 3, 2002, 9:53 AM
Quote Reply
Re: [RedRum] Recording uid without extra characters In reply to
use the variable $db_userid.
kellner
Quote Reply
Re: [LoisC] Recording uid without extra characters In reply to
Hi LoisC,

I've tried the following, however, it doesn't work!

Quote:
####### add userid in add form unless admin ###
unless ($per_admin) {
($auth_user_field >=0) and ($db_defaults{$db_cols[$auth_user_field]} = $db_userid);
}
####### end change #######

Please help.

Regard
Cary
Quote Reply
Re: [caryhung] Recording uid without extra characters In reply to
What is not working? Do you have the userid field defined in your .cfg file?

did you set this according to the field number for your userid?

$auth_user_field = 0;

When you entered the code within your add record form did you match the exact name of your userid field?

<input type="TEXT" NAME="Userid" VALUE="$rec{'Userid'}">

If your field is called 'userid' for example you would have to change the above to match your field name.

If you are logged in as admin it will not insert the userid, so to test this you would have to login as another user.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/

Last edited by:

LoisC: Mar 20, 2002, 7:35 AM
Quote Reply
Re: [LoisC] Recording uid without extra characters In reply to
Hi LoisC,

Quote:
did you set this according to the field number for your userid?

$auth_user_field = 0;

I set $auth_user_field = 6;

In HTML.PL (sub html_record_form):

<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font>Record ID:</FONT></TD>
<TD VALIGN="TOP" WIDTH="475">&nbsp;<$font>$rec{'ID'}</FONT><INPUT TYPE="hidden" NAME="ID" VALUE="$rec{'ID'}" SIZE="5" MAXLENGTH="8"></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Course Code:</FONT></TD>
<TD VALIGN="TOP">&nbsp;<$font>$rec{'Userid'}</FONT><INPUT TYPE="TEXT" NAME="Userid" VALUE="$rec{'Userid'}" SIZE="8" MAXLENGTH="10"></TD></TR>

However, the problem is the value of 'ID' can be displayed in Add Form, however, 'Userid' cannot.

Please help.

Cary
Frown
Quote Reply
Re: [caryhung] Recording uid without extra characters In reply to
Quote:
However, the problem is the value of 'ID' can be displayed in Add Form, however, 'Userid' cannot.


You're showing what entries you have in html.pl. What is your field definition in default.cfg?

NEVERMIND ... see in another thread that you have the definition as:

'Userid' => [ 6, 'alpha', -2, 15, 1, '', '']

Last edited by:

Karen: Mar 20, 2002, 8:09 PM
Quote Reply
Re: [caryhung] Recording uid without extra characters In reply to
Quote:
However, the problem is the value of 'ID' can be displayed in Add Form, however, 'Userid' cannot.


Are you requiring users to login before adding records?

It is VERY difficult to try troubleshooting problems without benefit of looking at the associated files. It would be much easier to help if your files could be saved as TEXT files and uploaded to an area of your server where they can be viewed.
Quote Reply
Re: [Karen] Recording uid without extra characters In reply to
Again, I have to ask .. are you trying to have this display while logged in as the 'admin'?

I use this code in many database and the userid shows up just fine in the add form.. UNLESS of course I am logged in as admin. I use the version which will not add the userid if I as admin am adding a record.

Try signing up as a new user and then going to the add form and see if their userid shows up as expected.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [Karen] Recording uid without extra characters In reply to
Hi Karen,

Quote:
'Userid' => [ 6, 'alpha', -2, 15, 1, '', '']

In my default.cfg:

'Userid' => [ 6, 'alpha', -2, 15, 1, '', '']

Exactly the same, right?

Regard
Cary
Quote Reply
Re: [Karen] Recording uid without extra characters In reply to
Hi Karen,

Quote:
Are you requiring users to login before adding records?

Yes!

Quote:
It is VERY difficult to try troubleshooting problems without benefit of looking at the associated files. It would
be much easier to help if your files could be saved as TEXT files and uploaded to an area of your server
where they can be viewed.

I will email the URL to you via email.

Thanks
Cary
Quote Reply
Re: [caryhung] Recording uid without extra characters In reply to
Quote:
Exactly the same, right?


Yep! As I mentioned when my post was edited, I saw that you had posted the field definition in another thread.
Quote Reply
Re: [LoisC] Recording uid without extra characters In reply to
Hi LoisC,

Quote:
Again, I have to ask .. are you trying to have this display while logged in as the 'admin'?

Well, I've tried to login both admin & common users. However, it displays nothing in Add form.

Please help.

Cary
Quote Reply
Re: [caryhung] Recording uid without extra characters In reply to
Try changing:

'Userid' => [ 6, 'alpha', -2, 15, 1, '', '']

to:

'Userid' => [ 6, 'alpha', 10, 15, 1, '', '']

As far as I understand marking fields as -1, or -2 only works when autogenerate is turned on. That is the only thing I can think of that would be causing problems.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [caryhung] Recording uid without extra characters In reply to
Cary, try making the following change in the form segment of html.pl.

Change:

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Course Code:</FONT></TD>
<TD VALIGN="TOP">&nbsp;<$font>$rec{'Userid'}</FONT><INPUT TYPE="TEXT" NAME="Userid" VALUE="$rec{'Userid'}" SIZE="8" MAXLENGTH="10"></TD></TR>

TO:

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Course Code:</FONT></TD>
<TD VALIGN="TOP">&nbsp;<$font>User ID:</FONT><INPUT TYPE="TEXT" NAME="Userid" VALUE="$db_uid" SIZE="8" MAXLENGTH="10"></TD></TR>
Quote Reply
Re: [LoisC] Recording uid without extra characters In reply to
Hi LoisC,

Quote:
'Userid' => [ 6, 'alpha', -2, 15, 1, '', '']

to:

'Userid' => [ 6, 'alpha', 10, 15, 1, '', '']

I've done this, however, it doesn't help.

UnsureCary
Quote Reply
Re: [Karen] Recording uid without extra characters In reply to
Hi Karen,

Quote:
TO:

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Course Code:</FONT></TD>
<TD VALIGN="TOP">&nbsp;<$font>User ID:</FONT><INPUT TYPE="TEXT" NAME="Userid" VALUE="$db_uid"
SIZE="8" MAXLENGTH="10"></TD></TR>

I've changed to:

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Course Code:</FONT></TD>
<TD VALIGN="TOP">&nbsp;<$font>$rec{'Userid'}</FONT><INPUT TYPE="TEXT" NAME="Userid" VALUE="$db_uid" SIZE="8" MAXLENGTH="10"></TD></TR>

It displays:

user.101668566123499
admin.(long number)

It seems I repeat astroboy5714's problem. Any help?

Cary
Quote Reply
Re: [caryhung] Recording uid without extra characters In reply to
Like Karen mentioned earlier, it's hard to do any more troubleshooting without seeing your files.

Could you save them as .txt files and provide the url to access your .cfg, html.pl and db.cgi files?

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [caryhung] Recording uid without extra characters In reply to
Check your messages.
Quote Reply
Re: [LoisC] Recording uid without extra characters In reply to
Cary, you have a hidden field at the top of your form ...

<input type=hidden name="uid" value="$WhateverYouHaveHere">

That hidden field is where you're getting the value from that is being used in the Userid field using the code segment I just provided to you. Try removing this hidden field from your form and attempt again to add a record.