FrontEndUsers to NMS (via SelfRegistration)

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

FrontEndUsers to NMS (via SelfRegistration)

Post by Ted »

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:

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']));
    }
}
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.
Last edited by Ted on Wed May 20, 2009 4:14 pm, edited 1 time in total.
JeremyBASS

Re: FrontEndUsers to NMS (via SelfRegistration)

Post by JeremyBASS »

sweet.. ;D thanks for sharing :)

Cheers
cms_man
Forum Members
Forum Members
Posts: 12
Joined: Mon May 04, 2009 8:00 pm

Re: FrontEndUsers to NMS (via SelfRegistration)

Post by cms_man »

Hi Ted ,

Thanks a lot  for  sharing the  code with the community. You really helped me lot.
I was  banging my head for couple of days how  to disable the user  if they decide to change their info and uncheck the box.
I have  the  following code that does not work for some reason. I hope  you  have the  solution.

Thanks in advance
Chris

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('newsletter', $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 disabled = 1 where email = ?', array($feu_user[1]['username']));
    }
}

tyman00
Power Poster
Power Poster
Posts: 906
Joined: Tue Oct 24, 2006 5:59 pm

Re: FrontEndUsers to NMS (via SelfRegistration)

Post by tyman00 »

Nice work Ted. I'll be bookmarking this thread for future use :)
If all else fails, use a bigger hammer.
M@rtijn wrote: This is a community. This means that we work together and have the same goal (a beautiful CMS), not that we try to put people down and make their (voluntary) job as difficult as can be.
cwboaze
New Member
New Member
Posts: 6
Joined: Wed Mar 03, 2010 3:53 am

Re: FrontEndUsers to NMS (via SelfRegistration)

Post by cwboaze »

would love to also have it run a event  OnDeleteUser to remove them from the newsletter if they are deleted.
cwboaze
New Member
New Member
Posts: 6
Joined: Wed Mar 03, 2010 3:53 am

Re: FrontEndUsers to NMS (via SelfRegistration)

Post by cwboaze »

would also love to have it where, a checkbox for signing up the newsletter, when they update their information if they uncheck it, it would unsubscribe them from NMS.
tyman00
Power Poster
Power Poster
Posts: 906
Joined: Tue Oct 24, 2006 5:59 pm

Re: FrontEndUsers to NMS (via SelfRegistration)

Post by tyman00 »

If all else fails, use a bigger hammer.
M@rtijn wrote: This is a community. This means that we work together and have the same goal (a beautiful CMS), not that we try to put people down and make their (voluntary) job as difficult as can be.
cwboaze
New Member
New Member
Posts: 6
Joined: Wed Mar 03, 2010 3:53 am

Re: FrontEndUsers to NMS (via SelfRegistration)

Post by cwboaze »

Thanks for that reference, it helped a lot.

I can do most of this myself. I just don't know the available commands,
used through NMS

like $nms->AddUser

what are the others. ? RemoveUser,EditUser, so on. and their required parameters if I know this, I can do the rest myself.

Appreciate your help!!
cwboaze
New Member
New Member
Posts: 6
Joined: Wed Mar 03, 2010 3:53 am

Re: FrontEndUsers to NMS (via SelfRegistration)

Post by cwboaze »

can anyone supply me with these functions.?? if not, I'll read through the module code, and find it myself.
crosmuller
Forum Members
Forum Members
Posts: 59
Joined: Thu Jan 17, 2008 10:26 am

Re: FrontEndUsers to NMS (via SelfRegistration)

Post by crosmuller »

Great thanks!
Bilmartech
Forum Members
Forum Members
Posts: 50
Joined: Mon Feb 21, 2011 2:08 am

Re: FrontEndUsers to NMS (via SelfRegistration)

Post by Bilmartech »

Thanks for the Tip.. Been looking for this for a while...

Question.. Is there a way to do 1 of either of these:

1) Automatically have the box checked by default?
or
2) Simply automatically register them for the newsletter when they register since the people joining the site are all associates and the newsletter is simply included as a form of constant communication for the group?
tyman00
Power Poster
Power Poster
Posts: 906
Joined: Tue Oct 24, 2006 5:59 pm

Re: FrontEndUsers to NMS (via SelfRegistration)

Post by tyman00 »

You could use jQuery to check the checkbox.

Code: Select all

$('.checkbox').attr('checked','checked')
If all else fails, use a bigger hammer.
M@rtijn wrote: This is a community. This means that we work together and have the same goal (a beautiful CMS), not that we try to put people down and make their (voluntary) job as difficult as can be.
Bilmartech
Forum Members
Forum Members
Posts: 50
Joined: Mon Feb 21, 2011 2:08 am

Re: FrontEndUsers to NMS (via SelfRegistration)

Post by Bilmartech »

tyman00 wrote:You could use jQuery to check the checkbox.

Code: Select all

$('.checkbox').attr('checked','checked')
Thanks for the response.. so in the example code that ted posted.. would I insert this portion right after the:

//Did they click the checkbox?
if ($feu->GetUserPropertyFull('mailing_list', $params['id']))

or would it go into the code in another place.

Thanks again for the help...
Bilmartech
Forum Members
Forum Members
Posts: 50
Joined: Mon Feb 21, 2011 2:08 am

Re: FrontEndUsers to NMS (via SelfRegistration)

Post by Bilmartech »

Any help here.. I am lost right now trying to get this to auto check?
crosmuller
Forum Members
Forum Members
Posts: 59
Joined: Thu Jan 17, 2008 10:26 am

Re: FrontEndUsers to NMS (via SelfRegistration)

Post by crosmuller »

I put this in my template:

Code: Select all

</__body onload="
document.getElementById('m11515moduleform_2').m11515input_mailing_list.checked = true;
">
m11515moduleform_2 is the form id

m11515input_mailing_list is the checkbox name

Maybe not the best option but it works :).
Post Reply

Return to “Tips and Tricks”