I'm trying to build an edit form for specific users. For one type of user I want to hide password field for example

What I did is to create a module called profilechange.

Into profilechange.module I wrote this code :

function profilechange_form_alter(&$form, $form_state, $form_id) {
    if ($form_id == 'user-profile-form') {

So I enable the module and into my page--user--edit.tpl.php I've this code :

<?php print render($page['content']); ?>

It displays the default edit form. But password fields are not hidden.

That's why I need your help, I don't know why it does not work even if I clear the cache

  • try with unset() function
    – Shabir A.
    Dec 24, 2015 at 14:32
  • Notice that the correct form id should be user_profile_form in the if statement. Use low hyphens to refer to machine names.
    – argiepiano
    Dec 24, 2015 at 14:49

2 Answers 2


You also might try the user readonly module. It allows to disable or hide certain form fields for certain users.


You want to do this...

$form['account']['pass']['#access'] = FALSE;
  • If you're altering a form HOOK_form_alter() you set #access to FALSE.
  • If you're on the theme layer (theme function or file), you can use hide().

The '#access' property means the element is not rendered and the user submitted value is not taken into consideration See https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#access

The hide() function hides an element from rendering later in the process. See https://api.drupal.org/api/drupal/includes%21common.inc/function/hide/7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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