PHP to get 2 fields from user profile?

heather - May 11, 2008 - 12:05
Project:Automatic Nodetitles
Version:6.x-1.1
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

I am not sure if this is related to this topic http://drupal.org/node/183796 because I am not trying to use a CCK field.

Maybe this is impossible?

I want to pull 2 fields from the default user profile. But of course this doesn't work. .. (and I can't use token, since these values aren't available there)

<?php
 
global $user;
 
$title = ($user->profile-firstname . $user->profile-lastname);
  return
$title;
?>

- I am using the default user profile module to let registrants supply their first and last name (required)
- Approved users can create a "Bio" (using bio module). Since I don't want them to enter in their name again, I want to pull the first and last name from the default user profile they filled in during registration.

#1

williecoetzee - September 1, 2008 - 10:50

Hi,

I believe you might be looking for something like this..

global $user;
$profile = profile_load_profile($user);
$custom1 = $user->profile_custom1

To save an array of form data back into the profile:

profile_save_profile($record, $user, $category, $register = FALSE);

I got this from here: http://drupal.org/handbook/modules/profile as posted by agerson.

#2

jgarbe - June 30, 2009 - 05:36
Version:5.x-1.1» 6.x-1.1

Ok, I'm stumped too. I'm not getting any strings for any of these (the field I want is in the user profile area, no group, called profile_firstname)

$profile['profile_firstname']

$account->profile_firstname

This is the code I'm using...global $user should be extraneous to it I think but I threw it in there to make sure.

<?php
global $user;
print (
$profile['profile_firstname']."'s Request");
?>

For the record, $account->profile_firstname works just fine for use in the user-profile.tpl.php template override files. What am I missing? Thanks for such a useful module!

 
 

Drupal is a registered trademark of Dries Buytaert.