Adding users to groups while registering.

Permalink
Hello,

I've overridden the single_pages/register.php and controller/single_pages/register.php.
Then I've added two radio buttons to my registration form, to have a user select one of two groups to be added to.
I'm able to fetch the value of the radio button in the controller page, and have tested this by appending the value to the username while registering, this works.

However after this code in the controller:
// now we log the user in
if ($config->get('concrete.user.registration.email_registration')) {
    $u = new User($this->post('uEmail'), $this->post('uPassword'));
} else {
    $u = new User($this->post('uName'), $this->post('uPassword'));
}


I've added this piece of code, to add users into the specified group.
if( $this->post('uGroup') == "group1" ) {
    $g = Group::getByName('group1');
} else {
    $g = Group::getByName('group2');
}
$u->enterGroup($g);


Also, i've added
use Group;

to the top of the file, and changed Concrete\Controller\SinglePage; to Application\Controller\SinglePage;

Can anyone tell me what i'm doing wrong here?