How do I put new users automatically into different groups when event wont fetch $u->getAttribute()?

Permalink
Hi,

I am trying to code an event that fires upon on_user_add... I would like to add the users to certain grooups depending on what they answer to a selectbox in the register form... this will not work out for me though, because I can't fetch any $u->getAttribute() from the just created user.. I can get anything else like $u->getUserEmail() and such, just not the getAttribute...

So am I doing anything wrong, or is there a better way to divide new members into different groups on registration... (I want them to be added to the group of their belonging apartment)

this is my code:

<?php 
class ApplicationUser extends Object {
  public function setupUserJoinInfo($ui)
  {  
     Loader::model('groups');
     $u = $ui->getUserObject(); 
    $ui1 = UserInfo::getByID($u->getUserID());
     // add new user to groups
     $g1 = Group::getByName('unvalidated');
     if (is_object($g1)) { 
        $u->enterGroup($g1);
     }     
    if($ui->getAttribute('afdeling') == 'Ungdom') {
       $g2 = Group::getByName('Ungdom');
         if (is_object($g2)) {


thank you in advance

pixel8
 
dg1 replied on at Permalink Reply
I'm not sure if this is exactly the same as you, but I had a similiar problem when trying to retrieve attributes in the on_user_add event handler. It turns out they weren't saved yet at the point where the event handler runs so I had to move my code to do_register (controllers/register.php) after the attributes are saved. For more details, see the thread I had started at
http://www.concrete5.org/community/forums/customizing_c5/problem-wi... Hopefully, this will help you.