I want to set the current user as a default for this field.

I was hoping the following code should do it , but no...

array(
  0 => array('uid' => $user->uid)
);

(note that I am a drupal newbe :-) )

Thx

Comments

pete-drupal’s picture

This works for me: (maybe you forgot 'global'; see code below)

  1. Logged in as admin, configure a CCK User Reference field.
  2. Go to URL http://dev.server.lan/admin/content/types/CCKtype/fields/CCKUserRefField

    where CCKtype is the name of the CCK type and CCKUserRefField the name of the CCK field

  3. Go to admin setting: Widget > Default value > Php code
  4. Enter custom code in order to define a non-standard default value for the CCK User Reference (without php-tags as per instructions):
    global $user;
    return array(0 => array('uid' => $user->uid));
pieter_degraeuwe’s picture

Status: Active » Closed (fixed)

Perfect !
(I indeed forgot the 'global' ...)

Thanks a lot !