Profile: extending user account information

Last modified: November 10, 2009 - 03:05

The profile module lets your users share information about themselves. You set up forms for them to fill in. Users tell about themselves by filling in your forms on the edit tab of their "My Account" page. And what each user tells will be visible to the rest of the users on your site, to the extent you choose when you design the forms.

You can enable the profile module on the modules page:

  • Drupal 5.x and above: Administer > Site Building > Modules
  • Drupal 4.7 or below: Administer > Modules

When you set up the forms for user profiles (at Administer > User Management > Profiles), you can define custom fields (for example, for name, age, and country). To do this, you can make use of fields of the following types:

  • single-line textfield
    Example: You want to ask your user's name
  • multi-line textfield
    Example: You want to ask an open-ended question: "What would you most like to do to make this a better community?"
  • checkbox
    Example: You want to say, "Please tick this box if you've ever been to Brazil."
  • list selection
    Example: You want to ask, "Which of these colors do you most prefer--red, blue or green?"
  • freeform list
    Example: You want to ask your user for a list--"What languages do you speak?"
  • URL
    Example: You want to ask, "What is the address of your personal website?"
  • date
    Example: You want to ask, "When were you born?"

You can have as many fields as you want, using any of these types as many times as you want. And you can put each field into the order you want by specifying its "weight."

Each time you add a field, you are asked to specify its "category." This allows you to divide each user's profile into more than one section. For example, you might divide the profile into two sections, one on "Community interests," the other on "Professional skills." So as you define each field, you assign it to one of these two categories. Drupal will then typically display each user's profile page with two separate sections--one for "Community interests," another for "Professional skills"--each with its own set of information, derived from the fields you have defined and your user has filled in.

You can mark a field as being required ("The user must enter a value"). And you can specify that when new users register, a field be shown for them to fill in.

If both the profile module and the menu module are enabled, from the Menus page (Administer > Site Building > Menus) you can enable the item User list within the Navigation Menu. This will take people to a page where they can see a list of your users. A person who has permission can click on the name of any user in the list to view that user's profile.

The option to show this menu item may be disabled by default, but you can enable it. You can also rename "User list" to whatever you wish as well as move the menu item to whatever menu you like (e.g. Primary Links.)

On the permissions page (Administer > User Management > Access control) you can decide who is normally allowed to view the user profiles. (You'll find the permissions for profiles under "user module.") In any case, the profiles are always accessible to your site administrators.

Contributed modules can also deploy the fields in user profiles to do much more with them. Such modules, for example, can help community-based sites identify and organize users through their profile fields.

Custom Profile Code Examples

To get custom profile values in code:

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);

How to make profile fields vary based on user info

longislandbassist - August 7, 2009 - 14:29

Let's say I have several different types of users. For example, Baseball Players and Football Players (to use a sports metaphor). Baseball Players should have certain fields that Football Players should not have, and vice versa. Baseball Players might have "favorite brand of mitt" and "bats righty or lefty", while Football Players might have "Plays offense or defense" and "favorite brand of helmet".

Can I have different types of user profiles, which are determined by certain basic user information? If I set up my user account as "Baseball player", then I am only shown the profile fields relevant to that setting.

TIA!

How about Content Profile?

ck9 - August 16, 2009 - 08:21

How about Content Profile? Using nodes + CCK seems like the best way to achieve that.

How did you go with different profiles for different user types?

k7n4n5t3w4rt - September 29, 2009 - 06:49

hey longislandbassist, did you settle on an approach for this? I'm thinking that the best solution might be to make some content types for each type of user and associate them with system users...

Have you tired the Profile Role module

tsega - November 8, 2009 - 11:23

http://drupal.org/project/profile_role

It gives you the ability what type of profile field groups will be availabe to what kind of user roles, as for your example you would have two roles Baseball Players and Football Players, then you enable the core Profile module, add in fields, in the role tab provided in at admin>user>profile you can pick which user role see which field group, as simple as that.

hope this helps...

How to resize the fields width

sanjanaa - September 16, 2009 - 10:04

How to resize the profile module's fields width?

The code snippet added above

hga77 - October 20, 2009 - 15:44

The code snippet added above seems to be wrong:

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

The 2nd line of code where a variable $profile is declared, there is no need for this since the function profile_load_profile doesnt return a value.

Instead just do this:

profile_load_profile($user);

You can load the profile

mheacock - January 13, 2010 - 16:44

You can load the profile variables into ANY object that has a uid property.

For instance, in forum-topic-list.tpl.php, you can load the profile variables for the topic creator into the $topic variable.

profile_load_profile($topic);

Or create a temp class with a uid property.

class temp_profile {
  public $uid = 0;
}

foreach ($topics as $topic) {
  $creator = new temp_profile();
  $commenter = new temp_profile();
  $creator->uid = $topic->uid;
  $commenter->uid = $topic->last_comment_uid;
  profile_load_profile($creator);
  profile_load_profile($commenter);
  ... do stuff ...
}

issues with the core module Profiles in multisites setup

otavio - November 10, 2009 - 15:45

We've upgraded and merged serveral 5.x sites to 5.20 same code base w/ dif DBs.

Now, eventhough the Profile module is active, the Profile administration in not visible in the Admin menu nor the custom User fields are visible.

The same is happening for all sites in that code base.

I moved back one of the sites to "standalone" rather than multistis and the Profile menu reapered. In both standalone and multisite, the perms for the Profile core module is identical.

So, in the multisite instal, the module appears to be active but does not show it's interface.

Any clues? or ideas on how to troubleshoot this?

I haven't seen anybody else with this issue.

thanks!!!!

silly question?

andybill - January 29, 2010 - 20:11

I've created some profile fields (profile_firstname, profile_surname, profile_dob) and want to use them as tokens in notifications (e.g. [profile_firstname]. What's the quickest / easiest way to do that without changing code - I tried the token_profile.inc code that's referenced elsewhere but I ended up with [profile_firstname] in the text of the message .... what am I missing ...

i'm trying to do the same thing

bocalig - February 4, 2010 - 03:33

Is this possible? I'm trying to find a way to display the profile_firstname on my custom block.tpl.php.

yea I'm a total noob at this. Right now I have the username displayed. My client would like to display the customer's real name.

This is what I have to display the username:

<?php
echo $data['user']->name;
?>

Is there a way to access the profile_firstname field instead of the username?

--jBocalig

 
 

Drupal is a registered trademark of Dries Buytaert.