This topic is locked

insert log in name into text field

1/8/2007 8:34:46 PM
PHPRunner General questions
C
chugha author

hi
can anybody help med
i want to insert log in name of logged user(current user ) in to my text field
i mean when i am entering some values into my new page (add page) i want to use on coloun posted by and i want this text filed should conatain the user name (looged user name) without inseting it.

J
Jane 1/9/2007

Ric,
you can do it using events.

Proceed to the Events tab. select Before record added event and add your code in it.

Here is a sample:

function BeforeAdd(&$values)

{

$values["FieldName"]= "logged ".$values["FieldName"];

return true;

}



where FieldName is your actual field name.

3
3dwizard 12/10/2007

Hello,
I tried the code below several times in many different variations. I try to assign an event to a specific field as stated, but when I publish and try all I get is under user to say "logged", not an actual name the user has logged in. Any ideas?
Project: I am building a simple web database. Where users will be able to post their data. Once they post it I need one field to state their username. After that I will make it read only. At leats that is my idea, if you have something better please suggest. Thank you...
For the code below I go to Events --> Before Record Added --> Custom Code --> and then I insert the code below. And I change my field name with an actual field name i am using. Am I doing this right?

Ric,

you can do it using events.

Proceed to the Events tab. select Before record added event and add your code in it.

Here is a sample:
where FieldName is your actual field name.

Sergey Kornilov admin 12/10/2007

Post your code here.

3
3dwizard 12/10/2007

This is the code I am using (basically taken from the previous post)...
[codebox]function BeforeAdd(&$values,&$message,$inline)

{

$values["User"]="logged".$values["User"];

return true;

} // function BeforeAdd[/codebox]
So as of now. This is how it works. In the box nothing shows. Once I add it. There is "logged" word on it. Even if I put per say word "text" in the box, once I add it it will say "textlogged"
Thx

J
Jane 12/11/2007

Hi,
try to use this code:

$values["User"]="logged ".$_SESSION["UserID"];

return true;

3
3dwizard 12/11/2007

I just actually removed ("logged".)
$values["User"]="logged".$_SESSION["UserID"];
So the final code looks like this:
$values["User"]=$_SESSION["UserID"];

return true;
I made it read only and works perfect...

You can see it in Edit, View and List and it is always there for print purposes. Really great add-on.
Thx Jane

T
tototoo 12/11/2007

That's great! But, how would one display other data from the user table, such as their FirstName and LastName or Company?

J
Jane 12/12/2007

Hi,
to select another values from users table use this code:

global $conn;

$str = "select * from UsersTable where UserName='".$_SESSION["UserID"]."'";

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);
$values["User"] = $data["FirstName"]." ".$data["LastName"]." ".$data["Company"];