0

I want to hide fields such as password, email when a particular user tries to edit few fields of other users.

How can I achieve this?

1

Hi for this there is many possible way to achieve this you can use https://www.drupal.org/project/field_permissions/releases/7.x-1.0-beta2 (The Field Permissions module allows site administrators to set field-level permissions to edit, view and create fields on any entity.) or by custom module

 function mymodule_form_alter(&$form, $form_state, $form_id) {

  if ($form_id === 'you_form_id') {

  if (in_array('user_role_type', $user->roles)){
    //do stuff

     // Use var_dump  to dump the $form array to see the fields. 
     // var_dump ($form);

     unset($form['mail']);
     unset($form['pass']);
    }
  }
}
| improve this answer | |
  • i have tried with field permission and user protector modules and while editing other user automatically i could see this email and password field of other user. – neethu Jun 20 '16 at 11:46
  • another way is by form alter like$items['foo/bar/user'] = array( 'title' => 'Foobar', 'description' => 'List, add, and edit Foobars.', 'page callback' => 'foo_bar_function', 'access callback' => 'user_access', 'access arguments' => array('administer users'), ); – Naveen Jun 20 '16 at 11:50
  • sorry i am not getting because i have no idea how to do this form alter n where exactly what to do, if u can tell me or explain it would be great helpful – neethu Jun 20 '16 at 11:56
  • 1
    check above code just replace authenticated user to your user access to hide fields – Naveen Jun 20 '16 at 12:08
  • this piece of code where to paste or modify is it in user.module?sorry if i am being dumb – neethu Jun 21 '16 at 6:19

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