I'm attempting to list out all the fields a user profile object would have into a tableselect. This will be displayed on the configuration screen of a module that I have been building. I have managed to make a tabelselect with checkboxes and dropdowns in it. That part I got down.

The part that I thought would be easy and ended up getting me stuck is getting an array of the fields a profile has. This would include any user made profile fields. Is there a simple way to get an array of the profile fields without needing to relate it to a user? The module would need this list on the front end for anonymous users so comparing it to the user would not work.

I don't need the values of any fields just the names and type of field maybe some settings like max and min. But will not need the value of any set user.

1 Answer 1


It sounds like you want field_info_instances():

$fields = field_info_instances('user', 'user');
$rows = array();

foreach ($fields as $field_name => $field) {
  $rows[] = array(
    $field_name,              // eg. 'field_my_field'
    $field['label'],          // eg. 'My Field'
    $field['description'],    // eg. 'A Description of my Field'
    $field['default_value']   // eg. 'default value'
  • this works but only shows me an array of the custom fields i added. Is there a way to include the default fields drupal has built into the profile as well? for example the avatar, username, password field, email, One array that has a list of all available fields for a profile. Jul 14, 2015 at 18:32
  • I would probably just hardcode those because they are pretty standard and usually don't change: username, password, email, status, roles, signature, picture. user_account_form() (api.drupal.org/api/drupal/modules!user!user.module/function/…) essentially does this - it hardcodes the standard form fields, then attaches the generated Field API form elements via field_attach_form (see api.drupal.org/api/drupal/modules!user!user.pages.inc/function/…).
    – BrianV
    Jul 14, 2015 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.