For my CCK select list options, I did:

//just making up firstName field to simplify example
$sql = "SELECT uid,firstName FROM users";
while($row = db_fetch_object($result)) {
  $uids[$row->uid] = $row->firstName;
return $uids;

This returns something like:

'1' => 'joe'
'2' => 'bob'
'3' => 'sarah'

Now in CCK, how do I programmatically set the the logged in user's id to be the default selected from the select list? Furthermore, CCK's example of a default return value makes no sense to me:

return array(
  0 => array('value' => value for value),
  // You'll usually want to stop here. Provide more values
  // if you want your 'default value' to be multi-valued:
  1 => array('value' => value for value),
  2 => ...

I know I can do this with hook_form_alter, but I am trying this WITHOUT writing any custom module so I can learn CCK and make it easy for my future devs.

2 Answers 2


How about this:

global $user;
return array(
  0 => array( 'value' => $user->uid )
  • Unfortunately that is not the right syntax that CCK wants. Any other suggestions?
    – user785179
    Jan 13, 2012 at 18:33
  • 1
    Sorry, my bad... check the edits!
    – rafaelcr
    Jan 13, 2012 at 18:52

What CCK is looking for is a keyed array as you COULD have multiple values selected/selectable for the field, but in this case I am thinking you have only one, or the '0'th value. Thus, if all you are looking for is the current user id, you could return it this way as the default value:

global $user;
$vu=array('value' => $user->uid);

return array(0 => $vu);
  • Thank you! This is good to know in treating an individual value
    – user785179
    Jan 13, 2012 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.