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));
That's as far as I got. Sorry.
Quoting Chris McCreery chris.mccreery@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/
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@users.sourceforge.net wrote:
Quoting Chris McCreery chris.mccreery@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/ ]
Ok so I thought it was this but I really have no idea what's going on. I assumed that setting uid to $user=>uid would make that my default value for the cck field but I still the the aforementioned error.
global $user return array( 0 => array('uid' => $user=>uid), );
Thanks Chris
On 11/1/07, Chris McCreery chris.mccreery@gmail.com wrote:
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@users.sourceforge.net wrote:
Quoting Chris McCreery chris.mccreery@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
Quoting Chris McCreery chris.mccreery@gmail.com:
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?
$ret[] = array('uid'=>$u->uid,'name'=>$u->name);
Yes the global $user exists. I'm not familiar with CCK user reference but was giving you code based on your earlier example and your stated requirement.
HTH, Earnie -- http://for-my-kids.com/ -- http://give-me-an-offer.com/
Thanks but still no luck just that same error. Since I'm just trying to specify the default for this field and it is already getting the possible users to reference am I just trying to specify the default value? If so then do I need to run a query or just tell Drupal which uid I'd like to use? Would the following work? ( it doesn't but that just might be my syntax.
global $user return array( 0 => array('uid' => $user=>uid) );
On 11/1/07, Earnie Boyd earnie@users.sourceforge.net wrote:
Quoting Chris McCreery chris.mccreery@gmail.com:
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?
$ret[] = array('uid'=>$u->uid,'name'=>$u->name);
Yes the global $user exists. I'm not familiar with CCK user reference but was giving you code based on your earlier example and your stated requirement.
HTH, Earnie -- http://for-my-kids.com/ -- http://give-me-an-offer.com/
-- [ Drupal support list | http://lists.drupal.org/ ]
Quoting Chris McCreery chris.mccreery@gmail.com:
Thanks but still no luck just that same error. Since I'm just trying to specify the default for this field and it is already getting the possible users to reference am I just trying to specify the default value? If so then do I need to run a query or just tell Drupal which uid I'd like to use? Would the following work? ( it doesn't but that just might be my syntax.
global $user return array( 0 => array('uid' => $user=>uid) );
Yes, based on what you've said. You need a ; after global $user. Maybe you don't need to global $user; at all. Or you can ``$user = $GLOBALS['user'];''.
Earnie -- http://for-my-kids.com/ -- http://give-me-an-offer.com/
Grrrrrrrrrrrrrrrrrrrrrrrrrrr, ok nothing seems to work everything I put in there gives me the same error.
This is what I have now.
global $user; return array(0 => array('uid' => $user=>uid));
On 11/1/07, Earnie Boyd earnie@users.sourceforge.net wrote:
Quoting Chris McCreery chris.mccreery@gmail.com:
Thanks but still no luck just that same error. Since I'm just trying to specify the default for this field and it is already getting the
possible
users to reference am I just trying to specify the default value? If so
then
do I need to run a query or just tell Drupal which uid I'd like to use? Would the following work? ( it doesn't but that just might be my syntax.
global $user return array( 0 => array('uid' => $user=>uid) );
Yes, based on what you've said. You need a ; after global $user. Maybe you don't need to global $user; at all. Or you can ``$user = $GLOBALS['user'];''.
Earnie -- http://for-my-kids.com/ -- http://give-me-an-offer.com/
-- [ Drupal support list | http://lists.drupal.org/ ]
Le jeudi 01 novembre 2007 à 16:28 -0400, Chris McCreery a écrit :
Grrrrrrrrrrrrrrrrrrrrrrrrrrr, ok nothing seems to work everything I put in there gives me the same error.
This is what I have now.
global $user; return array(0 => array('uid' => $user=>uid));
Maybe try array('uid' => $user['uid'])
Ok I'm so lost here, does anyone know what I should be putting in here.
So far I have
global $user; array ( 0 => array ('uid' => $user=>uid));
Do I need return array? No idea what the format should be.
On 11/1/07, Xavier Bestel xavier.bestel@free.fr wrote:
Le jeudi 01 novembre 2007 à 16:28 -0400, Chris McCreery a écrit :
Grrrrrrrrrrrrrrrrrrrrrrrrrrr, ok nothing seems to work everything I put in there gives me the same error.
This is what I have now.
global $user; return array(0 => array('uid' => $user=>uid));
Maybe try array('uid' => $user['uid'])
-- [ Drupal support list | http://lists.drupal.org/ ]
Le jeudi 01 novembre 2007 à 18:44 -0400, Chris McCreery a écrit :
Ok I'm so lost here, does anyone know what I should be putting in here.
I'd say:
global $user; return array(0 => array('uid' => $user['uid']));
but that's just from what you said in an earlier post. I don't know much in Drupal.
Xav
On 11/2/07, Chris McCreery chris.mccreery@gmail.com wrote:
Ok I'm so lost here, does anyone know what I should be putting in here.
So far I have
global $user; array ( 0 => array ('uid' => $user=>uid));
Do I need return array? No idea what the format should be.
Global $user is an object, not an array, so the user id is $user->uid
Besides that, I can't say whether you need to return or to print something. I am not sure what you are trying to do, what errors exactly you are getting, or what doesn't work as it should.
On 11/1/07, Xavier Bestel xavier.bestel@free.fr wrote:
Le jeudi 01 novembre 2007 à 16:28 -0400, Chris McCreery a écrit :
Grrrrrrrrrrrrrrrrrrrrrrrrrrr, ok nothing seems to work everything I put in there gives me the same error.
This is what I have now.
global $user; return array(0 => array('uid' => $user=>uid));
Maybe try array('uid' => $user['uid'])
-- [ Drupal support list | http://lists.drupal.org/ ]
-- Chris McCreery -- [ Drupal support list | http://lists.drupal.org/ ]
Thanks for the replay. I have created a CCK field for User Reference. Right now it displays all possible users to select. I am trying to set the default selected user to the current user. I go to the content type I created and then select the field to configure. I have the option for a default value, it lets me select a specific user or I can enter php code to make this dynamic. So I would like to set the default selected item to be the current user. All the suggestions I've tried in previous replies all result in the following error when I submit the change to the custom field
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 :
Any help would be awesome because as you can see I have limited coding skills.
Thank you so much.
On 11/1/07, Cog Rusty cog.rusty@gmail.com wrote:
On 11/2/07, Chris McCreery chris.mccreery@gmail.com wrote:
Ok I'm so lost here, does anyone know what I should be putting in here.
So far I have
global $user; array ( 0 => array ('uid' => $user=>uid));
Do I need return array? No idea what the format should be.
Global $user is an object, not an array, so the user id is $user->uid
Besides that, I can't say whether you need to return or to print something. I am not sure what you are trying to do, what errors exactly you are getting, or what doesn't work as it should.
On 11/1/07, Xavier Bestel xavier.bestel@free.fr wrote:
Le jeudi 01 novembre 2007 à 16:28 -0400, Chris McCreery a écrit :
Grrrrrrrrrrrrrrrrrrrrrrrrrrr, ok nothing seems to work everything I put in there gives me the same error.
This is what I have now.
global $user; return array(0 => array('uid' => $user=>uid));
Maybe try array('uid' => $user['uid'])
-- [ Drupal support list | http://lists.drupal.org/ ]
-- Chris McCreery -- [ Drupal support list | http://lists.drupal.org/ ]
-- [ Drupal support list | http://lists.drupal.org/ ]
On 11/2/07, Xavier Bestel xavier.bestel@free.fr wrote:
Any help would be awesome because as you can see I have limited coding skills.
Cog just told you to try:
global $user; array ( 0 => array ('uid' => $user->uid));
Either that, or (if you need a single expression)
array ( 0 => array ('uid' => ($GLOBALS['user']->uid)) );
Note the difference: the last "=" has been replaced with a "-".
HTH, Xav
-- [ Drupal support list | http://lists.drupal.org/ ]
Thanks guys but still the same none descriptive error. I tried both of the suggestions but no luck.
On 11/2/07, Cog Rusty cog.rusty@gmail.com wrote:
On 11/2/07, Xavier Bestel xavier.bestel@free.fr wrote:
Any help would be awesome because as you can see I have limited coding skills.
Cog just told you to try:
global $user; array ( 0 => array ('uid' => $user->uid));
Either that, or (if you need a single expression)
array ( 0 => array ('uid' => ($GLOBALS['user']->uid)) );
Note the difference: the last "=" has been replaced with a "-".
HTH, Xav
-- [ Drupal support list | http://lists.drupal.org/ ]
-- [ Drupal support list | http://lists.drupal.org/ ]
Same one I mentioned earlier, the "configure cck field" page reloads and at the top in nice red box is:
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 :
Thanks
On 11/2/07, Xavier Bestel xavier.bestel@free.fr wrote:
Le vendredi 02 novembre 2007 à 08:33 -0400, Chris McCreery a écrit :
Thanks guys but still the same none descriptive error. I tried both of the suggestions but no luck.
Please describe the non-descriptive error.
-- [ Drupal support list | http://lists.drupal.org/ ]
Try this:
global $user; return (array( 0 => array('uid' => $user->uid)));
On Nov 2, 2007 9:00 AM, Chris McCreery chris.mccreery@gmail.com wrote:
Same one I mentioned earlier, the "configure cck field" page reloads and at the top in nice red box is:
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 :
Thanks
On 11/2/07, Xavier Bestel xavier.bestel@free.fr wrote:
Le vendredi 02 novembre 2007 à 08:33 -0400, Chris McCreery a écrit :
Thanks guys but still the same none descriptive error. I tried both of the suggestions but no luck.
Please describe the non-descriptive error.
-- [ Drupal support list | http://lists.drupal.org/ ]
-- Chris McCreery -- [ Drupal support list | http://lists.drupal.org/ ]
Tada!!!! Awesome Jim, thank you and thank you to all of the rest of you for your time. Glad we( and by we I mean "all of you" ) figured it out.
On 11/2/07, Jim Li jimmydami@gmail.com wrote:
Try this:
global $user; return (array( 0 => array('uid' => $user->uid)));
On Nov 2, 2007 9:00 AM, Chris McCreery chris.mccreery@gmail.com wrote:
Same one I mentioned earlier, the "configure cck field" page reloads and
at
the top in nice red box is:
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 :
Thanks
On 11/2/07, Xavier Bestel xavier.bestel@free.fr wrote:
Le vendredi 02 novembre 2007 à 08:33 -0400, Chris McCreery a écrit :
Thanks guys but still the same none descriptive error. I tried both
of
the suggestions but no luck.
Please describe the non-descriptive error.
-- [ Drupal support list | http://lists.drupal.org/ ]
-- Chris McCreery -- [ Drupal support list | http://lists.drupal.org/ ]
-- [ Drupal support list | http://lists.drupal.org/ ]