1

i extended the add user field by adding a role field as part of the fields that will be displayed when you click create user in mydomain.com/user/register. With the addition of some rules, this helps me to assign automatic roles to registering users.

I however noticed that when you add user from the admin menu in People>Add user, this roles fields are added to the already existing fields. This is undesirable because the Add user page already have a section where you can pick the role. This therefore makes the form to have 2 different section where you can pick roles.

I want to hide my custom role field in mydomain.com/admin/people/create but show it in mydomain.com/user/register. Please how do I achieve this

0

Probably hook_form_FORM_ID_alter on user_register_form then some logic like

function MYMODULE_form_user_register_form_alter(&$form, &$form_state) {

  // Is logged in user admin.
  if (user_access('administer users')) {

    // Hide myfield.
    $form['myfield']['#access'] = FALSE;
  }
}

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.