-3

I need to show only a few fields on the user edit form: username, email, and password.

I want to have a user edit form on a different page & URL and not the default form where users shall be able to edit the username, password, and email address of their own account

How do I show only these fields and theme the page?

1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Aug 4 at 18:06

1 Answer 1

0

For the Drupal user form changes:

Try with HOOK_form_form_id_alter() in .module


    function MYMODULE_form_user_form_alter(&$form, $form_state, $form_id) {
      // Your code...
    }

or you can try HOOK_form_alter()

    function MYMODULE_form_alter(&$form, $form_state, $form_id) {
      if ($form_id == 'user_form') {
        // Your code...
      }
    }

e.g

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

      if (!\Drupal::currentUser()->hasPermission('administer users')) {

        $form['field_organization_name']['widget'][0]['value']['#attributes']['disabled'] = 'disabled';  
        $form['field_organization_reference']['widget'][0]['target_id']['#attributes']['disabled'] = 'disabled';    

      }

}
1
  • Thanks for replying to the question, Apologies for not mentioning all the details earlier. I want to have a user edit form on a different page & url and not the default form where users shall be able to edit username, password and email address of the their own account.
    – Techpie22
    2 days ago

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.