I'd like to assign a specific role when a new user registers on my site using the regular registration form, beyond that of just "authenticated user".

How can I do this?


This is easily accomplished using the Rules module and setting up the "event" and "action" to behave the way you want it to behave.

I set it up so that "after saving a new user" I "added a user role" of the type that I wanted to have. That should do the trick.

  • Rules worked perfectly for what I needed because it was related to an e-commerce function.
    – Rob Orr
    Jan 29 '14 at 17:43

There's a module for that: Registration role.

Registration role lets an administrator select a role to automatically assign to new users. The selected role will be assigned to new registrants.


Another option is the Auto Assign Role module:

The Auto Assign Role serves three primary purposes. The first is to provide an automatic assignment of roles when a new account is created. The second is to allow the end user the option of choosing their own role or roles when they create their account. The third is to provide paths that will trigger a specific role when an account is created.


Try the Role field and Rules modules.

  • Create a role field, field_user_role (check boxes/radio button) in admin/config/people/accounts/fields
  • Create a rule in admin/config/workflow/rules, for the After saving a new user account even
  • Add _Entity has field > Entity: [account], Field: field_user_role_ as condition
  • Set a data value in Actions.
  • Can you give more information? Like what is the purpose of the role field in this case and where do you create the role field. Also useful would be how to assign this role using the rules module.
    – rooby
    May 11 '14 at 3:51

This is the most straightforward method, in a custom module.

function MY_MODULE_user_insert($account, $data) {
  $role = user_role_load_by_name('role-name');
  user_save($account, array('roles' => $account->roles + array($role->rid => $role->name)));

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.