Question: How can I assign a user group to a user when it's created through the front end?

EDIT: So a few more details. I see there are some great answers if you want to put all users in one group, but unfortunately that's not the case. I have different forms for different groups. Ideally I would like to have checkboxes on the front end you I can choose which group they are assigned to.

Answer: 
Under Settings > Users > Settings Tab there is an option to `allow public registration` and `Default User Group` with a drop down that lets you select a user group.

If you need more flexibility, you could also write a simple plugin with an `init` function defined in the primary plugin class that listens to the `saveUser` event, and assigns a user group based on some criteria that you define — perhaps test the value of a custom user field on users (that is a hidden field on the registration form).

\*UPDATED to assign group based on checkbox field called 'groupPreference':

```
namespace Craft;
class BusinessLogicPlugin extends BasePlugin {
  public function getName() {
     return 'Business Logic';
  }
  public function getVersion() {
     return '0.1';
  }
  public function getDeveloper() {
     return craft()->getSiteName();
  }
  public function getDeveloperUrl() {
     return 'http://mysite.com';
  }
  public function init() {
     parent::init();

     craft()->on('users.saveUser', function(Event $event) {

        // only fire if new user
        if ($event->params['isNewUser']) {

           // retrieve the userModel from the event
           $user = $event->params['user'];
           // retrieve the groupPreference field content
           $groupPreference = $user->getContent()->groupPreference;
           // create an empty array to store group ids
           $groups = array();

           // test for values in groupPreference array
           if (in_array("group1", $groupPreference)) {
              $groups[] = 1;
           }
           if (in_array("group2", $groupPreference)) {
              $groups[] = 2;
           }
           if (in_array("group3", $groupPreference)) {
              $groups[] = 3;
           }
           // assign the user to the groups
           $_POST['groups'] = $groups;
        }         
     });
  }
}

```

Haven't tested, but should be pretty close. Please comment if you see an error.

Keep in mind this event will fire, whenever this field is defined, even when saving a user through the CP. So you would have to delete the value before reassigning the user to a different group, or they will just get reassigned.
To have a new user automatically assigned to a user group, there are two easy ways to do it.

---

**(1) If the user registers through a front-end form:**

You can pre-set their user group by going to Settings > Users > Settings, and selecting the "Allow public registration?" checkbox. This will reveal a dropdown menu, from which you can select their destination user group...

![enter image description here](https://i.stack.imgur.com/6voMF.png)

Any users who sign up after that point will be automatically placed into that user group.

---

**(2) If the user is registered through the control panel:**

This was an issue I encountered on a few different sites, so I wrote a plugin to easily manage it...

> 
> [Auto-Assign User Group](https://github.com/lindseydiloreto/craft-autoassignusergroup)
> 
> 
> 

It's very easy to use, here's a screenshot:

![enter image description here](https://i.stack.imgur.com/UkY0Y.png)

Any users who are created after that point will be automatically placed into whatever user group(s) you specified.