Page 1 of 1

Default User ID

PostPosted: Wed May 16, 2012 6:07 pm
by Byrhtwulf72
Hi, is there a way for me to get a field from a table and set that as a default value for another field? What I want to do is get the ID of the user that's currently logged in and use that as the default value for another field. I plan to do this in the delegate class for the table, like this,

function User_ID__default(){
return '0001';

but I don't understand what I'm supposed to return. Thanks for your help.

Re: Default User ID

PostPosted: Thu May 17, 2012 9:34 am
by shannah
You could either user the fieldname__default() method (as you have mentioned) or use the beforeInsert() method to set the value before the record is inserted.

e.g.
Code: Select all
function beforeInsert($record){
    $user = Dataface_AuthenticationTool::getInstance()->getLoggedInUser();
    if ( $user ){
        $record->setValue('user_id', $user->val('user_id') );
    }
}

Re: Default User ID

PostPosted: Thu May 17, 2012 6:24 pm
by Byrhtwulf72
Thanks, that's just what I was looking for.