So, I setup FrontEndUsers, SelfRegistration and NMS. I just setup the standard FEU + SelfReg combo that's been discussed before. The only real thing of note was that I created a checkbox property called mailing_list and assigned it to my group.
I then setup a list in NMS, which gave me a mailing list id of 1 (keep info for later).
The next step was to create a user defined tag. I named it feu_to_nms or something -- doesn't really matter. I then used this code:
Code: Select all
if (!function_exists('MyGetModuleInstance'))
{
function &MyGetModuleInstance($module)
{
global $gCms;
if (isset($gCms->modules[$module]) &&
$gCms->modules[$module]['installed'] == true &&
$gCms->modules[$module]['active'] == true)
{
return $gCms->modules[$module]['object'];
}
// Fix only variable references should be returned by reference
$tmp = FALSE;
return $tmp;
}
}
global $gCms;
$nms = MyGetModuleInstance('NMS');
$feu = MyGetModuleInstance('FrontEndUsers');
if ($nms == FALSE || $feu == FALSE)
return false;
//Get User
$feu_user = $feu->GetUserInfo($params['id']);
//Do they really exist? Why are we here anyway?
if ($feu_user)
{
//Did they click the checkbox?
if ($feu->GetUserPropertyFull('mailing_list', $params['id']))
{
//Add user to NMS
//array(1) -- represents the id of the mailing list to add them to. Change the 1 to whatever you want.
$nms->AddUser($feu_user[1]['username'], array(1), $feu->GetUserPropertyFull('first_name', $params['id']) . " " . $feu->GetUserPropertyFull('last_name', $params['id']));
//Set the confirmed flag to true (they clicked the checkbox -- that's enough)
$db =& $gCms->GetDb();
$db->Execute('UPDATE ' . cms_db_prefix() . 'module_nms_users SET confirmed = 1 where email = ?', array($feu_user[1]['username']));
}
}
Then, I went to the Events list and found the "onUserRegistered" event. I edited it and added my feu_to_nms UDT to the list.
Now, whenever someone registers and clicks that check box, the event will fire, this code will run and the user gets added to the mailing list. Easy peasy.