This topic is locked

Default value

7/24/2008 11:48:46 PM
PHPRunner General questions
A
allan author

When a user login add a new data, I would like to have a default read only field in the add and edit page.
I can see there is read only field but how do I set the default value to the userid? It says it should be a valid php expression.
Guide please? Thanks

J
Jane 7/25/2008

Hi,
Use $_SESSION variables as default values.

For example $_SESSION["UserID"] contains username of logged user.

To set up default value as user ID select it from database and save in the new $_SESSION variable in the AfterSuccessfulLogin event on the Events tab:

global $conn;

$rs = db_query("select userid from UserTable where UserName='".$_SESSION["UserID"]."'",$conn);

$data = db_fetch_array($rs);

$_SESSION["IDuser"] = $data["userid"];

A
allan author 7/25/2008

How about I want more than 1 default value?
When a user add a data:
UserID:

UserName:

Data1:

Data2:
The user can only read the UserID and UserName field which will be auto filled leaving only Data1 and Data2 editable before add.
Thanks.

J
Jane 7/25/2008

Hi,
just use $_SESSION["IDuser"] as default value for UserID field, $_SESSION["UserID"] as default value for UserName field.

A
allan author 7/26/2008

Thanks