0

I know it is possible to hide most fields defined on /admin/config/people/accounts/fields on the user edit form /user/<uid>/edit by using the HOOK_form_alter function in a custom module like this targeting user_profile_form:

$form['field_account_myfield']['#access'] = 0;

But how to hide user profile form fields the right way (no CSS tricks)?

in my case the URL is /user/<uid>/edit/Profil. These are the fields you can define with the core profile module enabled on /admin/config/people/profile.

They are defined as object properties in the $form['#user'] object, e.g.:

$form['#user']->profile_address

unset() and ['#access'] = 0 does not seem to work.

  • Profile2 module? – Jimmy Ko Aug 4 '16 at 10:24
  • They are defined as object properties in the $form['#user'] object those are the values attached to an entity object; they're not related to form fields. Look in the $form array, you'll find the actual form fields in there somewhere – Clive Aug 4 '16 at 10:51
  • @Clive - I can't seem to find it. I tried searching for the profile field name (profile_myfield) on all forms on the page with Search Krumo, but the field name only appears in the $form['#user'] object. – benjamin_dk Aug 5 '16 at 7:45

Your Answer

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

Browse other questions tagged or ask your own question.