Drupal 7: disable email field on user profile form

Let’s say you don’t want your users, once they are registered, to change their email address. You can use hook_form_alter to disable the email field in the user’s account page.

/**
 * Implements hook_form_alter().
 */
function mymodule_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
  global $user;
  $roles = $user->roles;
  if(in_array('administrator', $roles)) {
    return;
  }
  $form['account']['mail']['#disabled'] = TRUE;
}
Advertisements
Posted in drupal

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: