2

Is there a way to allow a registrant to choose a user group in the registration form?

I tried using the following code but it didn't work:

<input type="hidden" name="userGroups" value="3">
1
3

As far as I know there is no way to do this without a plugin. However, developing a plugin for this is not difficult. In your form you would want to add an additional drop-down, multi-select, or checkbox field with your groups listed. Then in your plugin, create a listener in your plugin's init method that listens for the users.saveUser event, and dynamically assigns the user to the selected groups based on the user's selection. For an example see this post explaining how to respond to an onSaveUser event, and this post on assigning groups dynamically.

7
  • Thanks for your answer. I was wondering apart from this if it's possible to just assign a user to a user group from the front-end registration form? This way I could just build multiple registration forms, each assigning users to their own group. – Hasco Nov 11 '14 at 10:14
  • Unfortunately no. Without the aid of a plugin, its only possible to define a single default group for all public registrations. – Douglas McDonald Nov 11 '14 at 14:41
  • I thought I should add: for securities sake it would be best not to just allow any group ID to be assigned (i.e. don't just assign the group id that is passed from the form blindly), but rather selectively assign the groups that you do want to allow. Otherwise an attacker might be able to make themselves admin. – Douglas McDonald Nov 11 '14 at 16:13
  • I agree, so the attempt from my question is definitely a no go. In the meantime I wrote a plugin to solve my issue. Users are now able to select a group they want to sign up for in the registration form. I'll post it here as an answer. – Hasco Nov 11 '14 at 17:32
  • What you have above could work, just check (i.e. if 1 then group 1; if 2 then group 2; if 3 then redirect to department of homeland security cyberattack division) :) – Douglas McDonald Nov 11 '14 at 21:26

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.