emergingdzns - 1 year ago

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?

Answer

ryanthompson - 1 year ago

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

ryanthompson - 1 year ago

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

emergingdzns - 1 year 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 - 1 year ago

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

emergingdzns - 1 year ago

You sir are a rockstar! Thank you!!

ryanthompson - 1 year ago

Need to install @daviesgeek emoji plugin :-(

daviesgeek - 1 year ago

@ryanthompson yes you do ;)