This project is not covered by Drupal’s security advisory policy.

Account mail provides a Form API element to easily edit a user's email address.

Many sites which have registered users capture a number of profile fields about a user, such as name, job-title, email address, etc. Drupal typically handles this by having two tabs below user/123/edit: Account and Profile. This can prompt a usability issue, where users go to one URL to change their personal details, but a different URL to change their email address.

Typically I get asked to add an "Email address" field to an arbitrary form, such as their profile form. This usually meant a fair amount of custom code: a form_alter to add the new field, some validation handlers, submit handlers, etc. This module tries to abstract this out by providing a reusable Form API element for editing the 'mail' field for Drupal users.

For example, this is all you need to add the new account mail field (this example will edit and update the current user's email address):

function foo_form_some_form_id_alter(&$form, &$form_state) {
  $form['arbitrary_field'] = array(
    '#type' => 'account_mail',
    '#title' => t('Email address'),
  );
}

Here's an example for an arbitrary user:

function foo_form_some_form_id_alter(&$form, &$form_state) {
  // Assume that the UID is being populated elsewhere.
  $uid = $form['#user']->uid;

  $form['arbitrary_field'] = array(
    '#type' => 'account_mail',
    '#title' => t('Email address'),
    '#uid' => $uid,
  );
}

The default implementation does not provide any access control, but this is simple enough to add:

function foo_form_some_form_id_alter(&$form, &$form_state) {
  global $user;

  // Assume that the UID is being populated elsewhere.
  $uid = $form['#user']->uid;

  $form['arbitrary_field'] = array(
    '#type' => 'account_mail',
    '#title' => t('Email address'),
    '#uid' => $uid,
    // Users may only edit their own email addresses
    '#disabled' => ($user->uid != $uid),
  );
}

At present, the module only provides a Form API element. I intend to build a widget for the core Field API too.

Project information

Releases