Drupal - How to add extra fields to user profile?

I found the page hard to find, but at /admin/config/people/accounts/fields you can add fields to users.


A way to add user fields by code so you can put this in your module.

I have found this: field_create_field with in the comments a way to create a field for your user upon enabling your module:

/**
 * Implementation of hook_enable().
 */
function MYMODULE_enable() {
  // Check if our field is not already created.
  if (!field_info_field('field_myField')) {
    $field = array(
        'field_name' => 'field_myField', 
        'type' => 'text', 
    );
    field_create_field($field);

    // Create the instance on the bundle.
    $instance = array(
        'field_name' => 'field_myField', 
        'entity_type' => 'user', 
        'label' => 'My Field Name', 
        'bundle' => 'user', 
        // If you don't set the "required" property then the field wont be required by default.
        'required' => TRUE,
        'settings' => array(
           // Here you inform either or not you want this field showing up on the registration form.
            'user_register_form' => 1,
        ),
        'widget' => array(
            'type' => 'textfield',
            'weight' => '1',
        ), 
    );
    field_create_instance($instance);
  }
}

Profile in D7 is a bit weird. The profile2 module may do what you need.

Tags:

Users

7