0

I'm trying to hide non-admin users to view the email address field in the user section. I have the following hook. Right now, I have the current password hidden, but the email sends back a naughty validation requiring email to be added.

1

You can use similar code as below to hide pass and mail field with optional value.

//drupal_set_message('not admin!');
$form['account']['current_pass']['#required'] = FALSE;  
$form['account']['current_pass']['#access'] = FALSE;
$form['account']['mail']['#required'] = FALSE;    
$form['account']['mail']['#access'] = FALSE;



$form['#validate'] = array_diff($form['#validate'], array('user_validate_current_pass'));
$form['#validate'] = array_diff($form['#validate'], array('user_validate_mail'));
0

If you want to alter Drupal so that it doesn't require email addresses for users, you should look at this module: https://www.drupal.org/project/optional_mail

Read the module description carefully. User emails are deeply integrated into Drupal, and not having them can cause all kinds of unexpected problems.

0

You can use Field Permission module. It allows you to set permission for every field for every role in your website. So if you prevent non-admin users from accessing this field, they wont see it.

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.