Hi everyone,

How can I lock the default e-mail field (make it read only), so that users will not be able to change their e-mail addresses after registering.

Thanks

Comments

dotpex’s picture

In you custom module put:

<?php
function YOUR_MODULE_form_user_profile_form_alter(&$form, &$form_state) {
   
$form['account']['mail']['#disabled'] = TRUE;
}
?>
Ayesh’s picture

This will not work because when the field is disabled, browser does not send the value back, triggering a "Email field is required" error.
If you set #disabled, set #value as well.

// Ayesh
(Latest blog post: Drupal bad practices)

dotpex’s picture

Already using it.

Ayesh’s picture

There was a module to prevent users from editing certain fields, including email and password but I couldn't find that right now. See modules list.

Alternately you can use Email Change Confirmation module so everytime the user changes his email address, they have to verify it.
http://drupal.org/project/email_confirm

// Ayesh
(Latest blog post: Drupal bad practices)

stutibhavsar’s picture

There is a contributed module called "User Read-Only" (http://drupal.org/project/user_readonly)

I guess, this module will fulfill your requirement

Vahan Sargsyan’s picture

Thank you very much, this is that what I wanted

stutibhavsar’s picture

Pleasure! Nice to know that the module solved your problem.
All the best