[support] Default PHP Code for CCK field

Chris McCreery chris.mccreery at gmail.com
Thu Nov 1 17:50:45 UTC 2007


Thanks Earnie but I get the following error:

The default value php code returned an incorrect value
Expected format :

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

Returned value :

So I assume it needs an array and would the $global user already exist?

On 11/1/07, Earnie Boyd <earnie at users.sourceforge.net> wrote:
>
> Quoting Chris McCreery <chris.mccreery at gmail.com>:
>
> > I'm sure this is an easy one for you php coders but I'm a bit confused
> as to
> > what is currently populating my dropdown list as it is now.
> >
> > I have created a CCK for user reference, but I would like the default
> > value(or selected value) of the dropdown list to be the current user but
> > then list out the other users available, I'm not sure of the code to use
> for
> > the PHP Code portion of the default value.
> > global $user;
> > return array(0 => array('value' => $user->name));
> >
>
> <?php
> global $user
> $result = db_query('SELECT name FROM {users} WHERE name != \'%s\'',
> $user->name);
>
> $ret[] = $user->name
>
> while ($u = db_fetch_object($result)) {
> $ret[] = $u->name
> }
>
> return $ret;
> ?>
>
> You might also want to ``ORDER BY name'' when doing the select.
>
> Earnie -- http://for-my-kids.com/
> -- http://give-me-an-offer.com/
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>



-- 
Chris McCreery
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20071101/c86d0599/attachment.htm 


More information about the support mailing list