<p>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 <code>users.saveUser</code> event, and dynamically assigns the user to the selected groups based on the user's selection. For an example see this post explaining <a href="https://craftcms.stackexchange.com/questions/4259/is-it-possible-to-tell-if-a-user-was-registered-through-the-front-end-or-cp/4274#4274">how to respond to an onSaveUser event</a>, and this post on <a href="https://craftcms.stackexchange.com/questions/4197/restrict-user-editing-permissions-within-a-users-group/4202#4202">assigning groups dynamically</a>.</p>

CC BY-SA 3.0
2014-11-11T10:14:55.207Z
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
CC BY-SA 3.0
2014-11-11T14:41:12.477Z
Unfortunately no. Without the aid of a plugin, its only possible to define a single default group for all public registrations.
Douglas McDonald
CC BY-SA 3.0
2014-11-11T16:13:11.417Z
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
CC BY-SA 3.0
2014-11-11T17:32:34.710Z
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
CC BY-SA 3.0
2014-11-11T21:26:25.127Z
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
CC BY-SA 3.0
2014-11-11T22:00:42.513Z
Haha, what if I made 3 different forms which all have their own assigned user group, would that be more secure?
Hasco
CC BY-SA 3.0
2014-11-12T01:04:14.260Z
One form is fine. Just restrict what user groups they can be assigned to and your fine.
Douglas McDonald
CC BY-SA 3.0
2014-11-10T16:29:40.070Z
2014-11-10T16:29:40.070Z
2017-04-13T12:51:00.160Z
Douglas McDonald
<p>Is there a way to allow a registrant to choose a user group in the registration form?</p>

<p>I tried using the following code but it didn't work:</p>

<pre><code>&lt;input type="hidden" name="userGroups" value="3"&gt;
</code></pre>

CC BY-SA 4.0
2018-10-03T16:39:32.403Z
If you're looking for a **Craft 3** solution, check out my answer in this ticket: https://craftcms.stackexchange.com/a/27926/4433
Ryan
<users><form><user-groups><registration>
How can I get a user to choose in which group he registers using the User Registration Form
# How can I get a user to choose in which group he registers using the User Registration Form

(Asked by: username_0 on 2014-11-10)

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:

**Tags:** users, form, user-groups, registration

> **Comments:**
> **username_1**: If you're looking for a **Craft 3** solution, check out my answer in this ticket: https://craftcms.stackexchange.com/a/27926/4433  

---

## 1 answers

### Answer by username_2 on 2014-11-10. Score: 3 | Accepted answer

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](https://craftcms.stackexchange.com/questions/4259/is-it-possible-to-tell-if-a-user-was-registered-through-the-front-end-or-cp/4274#4274), and this post on [assigning groups dynamically](https://craftcms.stackexchange.com/questions/4197/restrict-user-editing-permissions-within-a-users-group/4202#4202).

> **Comments:**
> **username_0**: 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.  
> **username_2**: Unfortunately no. Without the aid of a plugin, its only possible to define a single default group for all public registrations.  
> **username_2**: 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.  
> **username_0**: 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.  
> **username_2**: 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) :)  
> **username_0**: Haha, what if I made 3 different forms which all have their own assigned user group, would that be more secure?  
> **username_2**: One form is fine. Just restrict what user groups they can be assigned to and your fine.  

---

