In a registration form with public signup possible, how do you set the user group for a particular form?
As a stop-gap I am attempting to use the following code:
function init()
{
craft()->on('users.saveUser', function(Event $event)
{
$user = $event->params['user'];
if( $user->leader == true )
{
craft()->userGroups->assignUserToGroups($user->id, array(2));
}
});
}
I created a field (lightswitch) called leader to enable me to check the value after saving the user and adding them to the group. The above code is not working though.
Using var_dump($user->leader)
I can see the true and false being returned on user, and also the $user->id
is returning the user's id, but the group (2) is not being assigned. Think I am missing something obvious. Thanks.