I think you're *very* close, but you need the user object, not the username so try this:
<?php
$user = $hook->getValue('register.user');
Hi Bob,
Thanks for that, I now get to the Registration Confirmation Page (I wasn't getting this before, but I was getting the confirmation email and the User was being created), but the User is still not added to the selected User Group. Is "register.user" a universal object or value, I don't have a field with this name in the form?
It should be available with getHook() according to the docs. If not, this should work:
<?php
$userName = $hook->getValue('register.username');
$user = $modx->getObject('modUser', array('username'=>$userName));
$userGroup = $hook->getValue('register.usergroup');
$user->joinGroup($userGroup);
$user->save();
?>
That means getObject() is failing. Either the username is not coming through from the register snippet, or the user doesn't exist yet.
Putting this in before the getObject() call should tell you which it is:
die('USER NAME: ' . $userName);
Hi Bob,
OK, so that produces the message "USER NAME:".
Maybe it would be better to put this selector in the Login.UpdateProfile form, that way the User already exists. I'll try it and see if it works that way.