I m using a content profile node type with CCK and email Field, and would like to make available in the content profile the email of the drupal user related to this content profile type. Each drupal users have a content profile , but they do not edit their content profile. An administrator user does the job, and complete content profile for each users.
The problem is that is i would like to autofill the email cck field with the drupal user's email.
When i use the php code in the default value :
global $user;
return array(
0 => array('your_field_name' => $user->mail),
);

it works but it autofills the email with the admin user email who is logged but not with the user profile i m editing. How can i code this in php, to retrieve the uid of the user i m editing his content profile and get his email field ? I have some useful information in the url http://mysite.com/user/30/profile/profile?uid=30&destination=user%2F30

Thanks in advance for your support

Comments

lorenlang’s picture

subscribing

fishfilet’s picture

subscribing

Bilmar’s picture

subscribing

YK85’s picture

+1 subscribing

criz’s picture

Try to load the node's author instead of the active user...

jeffschuler’s picture

Try this for your field's default value PHP:

// get uid from path args, which should be: "user/[uid]/profile/profile"
if (arg(0)=='user')
{
  $uid = arg(1);

  // get email address for uid
  $user = user_load($uid);
  $default = $user->mail;
}
else {
  $default = '';
}

// put the data into the required format
return array(
  0 => array('value' => $default),
);
amanire’s picture

FYI, if you're using an email CCK field, then the code in #6 will be

// get uid from path args, which should be: "user/[uid]/profile/profile"
if (arg(0)=='user')
{
  $uid = arg(1);

  // get email address for uid
  $user = user_load($uid);
  $default = $user->mail;
}
else {
  $default = '';
}

// put the data into the required format
return array(
  0 => array('email' => $default),
);
1kenthomas’s picture