Auto-assign role to user on registration
Created 7 years ago by emergingdznsI 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?
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!
Whoops sorry I updated my answer - was missing the first parenthesis. You can try the literal method setRoles
.
You sir are a rockstar! Thank you!!
Need to install @daviesgeek emoji plugin 🙍
@ryanthompson yes you do ;)
Try adding
.roles(['members'])
to your register form builder.