Auto-assign role to user on registration
Created 7 years ago by emergingdzns

I have a need to make sure that users that register on the site are assigned a specific role. Is it possible to do this in the form or something? Every user gets assigned to the "members" role on this site. But the system doesn't appear to have a default role which is clearly required in the admin panel for the Users module. If it's required shouldn't there be a setting somewhere that we can define the default role assigned on registration?

ryanthompson  —  7 years ago Best Answer

Try adding .roles(['members']) to your register form builder.

emergingdzns  —  7 years ago

Ok. Does that go inside the .redirect() bit? Here's my current registration form callout: {{ form('register').redirect(request_get('redirect', '/some/page/'))|raw }} I tried it like this: {{ form('register').redirect(request_get('redirect', '/healthguide/view/'~guide_hash)).roles['members']|raw }} But the form wouldn't show up. So I tried it inside the redirect() like this: {{ form('register').redirect(request_get('redirect', '/healthguide/view/'~guide_hash).roles['members'])|raw }} The form showed up but the role didn't get added.

Sorry for being a dunce on this. Appreciate the help!

ryanthompson  —  7 years ago

Whoops sorry I updated my answer - was missing the first parenthesis. You can try the literal method setRoles.

emergingdzns  —  7 years ago

You sir are a rockstar! Thank you!!

ryanthompson  —  7 years ago

Need to install @daviesgeek emoji plugin 🙍

daviesgeek  —  7 years ago

@ryanthompson yes you do ;)