FrontEndUsers to NMS (via SelfRegistration)
Posted: Wed May 20, 2009 4:06 pm
I'm in the process of setting up a paid registration site. One of the things that I wanted to do was set it up so that users who register have the option of signing up for a mailing list.
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:
This code makes a lot of assumptions, so you will have to change it to taste. For instance, I'm concatinating my first_name and last_name properties to create a name in my NMS user. I have FEU setup to use email address as the username -- if you don't, then you'll have to make some adjustments for that as well. There is also a slight hack in there to set the user as confirmed, since NMS's API doesn't give me the option on user creation. Also, look at the note for which mailing list id to use.
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.
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.