We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    Hi I'm trying to assign new users to a user group on a new registration based on a form field selection, I have this:

    [[!Register? 
    	&submitVar=`login-register-btn` 
    	&activationResourceId=`211` 
    	&activationEmailTpl=`lgnActivateEmailTpl` 
    	&activationEmailSubject=`Thanks for Registering!` 
    	&activationttl=`1440` &submittedResourceId=`212` 
    
    	&emailField=`email` 
    	&preHooks=`RegisterUserGroup` 
    	&customValidators=`agreeEULA` 
    	&usergroups=`[[+group]]`
    ]]
    


    in the RegisterUserGroup snippet, I just set a hook called 'group', the group selection will show up on the page, [i.e. the hook is being passed] but the user is not added to the group on registration [i.e. the hook is not picked up by the !Register call]

    What is the correct way to do this?

    -thanks
    -sean
      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525
      • 3749
      • 24,544 Posts
      I think you want a postHook with something like this (untested):

      <?php
      $user = $hook->getValue('register.user');
      $user->joinGroup($hook->getValue('RegisterUserGroup'));
      $user->save();
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 30912
        • 463 Posts
        I had a similar problem which was solved in another thread but heres my solution

        $user = $hook->getValue('register.user'); // the new registered user
        $group = $hook->getValue('product'); //this is the field they are selecting
        //$modx->log(modX::LOG_LEVEL_ERROR, 'group : '.$group); // this line just to return thr value in your error.log
        if(isset($group)){
            $user->joinGroup($group);
        //$modx->log(modX::LOG_LEVEL_ERROR, 'user as joined group : '.$group); // idem
        }
        return true;


        form snippet

        <label for="product">Product* </label>
                <select name="product:required" id="product">
                  <option selected=""> </option>
                  <option value="Group 1" [[!+product:FormItIsSelected=`Group 1`]]>Group 1</option>
         <option value="Group 2" [[!+product:FormItIsSelected=`Group 2`]]>Group 2</option>
        </select>
                  


        obivoulsy make sure your usergroup names match

        call:

        [[!Register? &submitVar=`registerbtn` &activationResourceId=`14` &activationEmailTpl=`My_lgnActivateEmailTpl` &activationEmailSubject=`Please activate your account` &submittedResourceId=`13` &activationttl=`10080` &postHooks=`UserGroup` ]] 


        @BobRay, i think you helped in this solution