10

Is there any way I can restrict users from certain role to change their email address. Once they are registered I need them no to be able to change it in the edit settings page. I found how to restrict to change the username but not the email.

I am using Drupal 7. Thanks in advanced :)

8

Another way is programmically in your custom module

function mymodule_form_alter(&$form,$form_state,$form_id) {
   global $user;
    if ($form_id == "user_profile_form") {
       if(in_array('your role',$user->roles) && isset($form['account'])) {
           $form['account']['mail']['#disabled']=TRUE;
          }
      }
 }
5

Use the User protect module:

This module allows fine-grained access control of user administrators, by providing various editing protection for users. The protections can be specific to a user, or applied to all users in a role.

  • I downloaded this module but it didn't do what was required - it is unable to prevent a user from changing their own password. Rather, it prevents admin roles from changing OTHER user's passwords. – littledynamo Oct 14 '13 at 14:07
3

zhilevan – thanks for the nice code to get me started in solving this problem quickly. I have a site where there is a generic user role "client" login so that clients can upload and download files. The user account will be shared between potentially many clients for a "one off" upload or download and we don't want them to alter the user name, password or any other stuff for this generic account. I'm sure there are more elegant ways to do this but here's my code for "shutting the edit option down" based on user role. (I tried the user protect module, but couldn't get it to work). Here's my code in case anyone else finds it useful.

function mymodule_form_alter(&$form,$form_state,$form_id) {
   global $user;
    if ($form_id == "user_profile_form") {
       if(in_array('Client',$user->roles) && isset($form['account'])) {

           $form['account']['name']['#disabled']=TRUE;
           $form['account']['current_pass']['#disabled']=TRUE;
           $form['account']['current_pass']['#description']='';
           $form['account']['mail']['#disabled']=TRUE;

           unset($form['picture']);
           unset($form['overlay_control']);
          }
      }
 }
  • :). your welcome. – Yusef Nov 28 '13 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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