Page 1 of 1

Calling code from other modules

Posted: Mon Sep 10, 2007 11:01 pm
by rmelberg
I am working on integrating the Form Builder and Newsletters Made Simple modules.  What I want is a single form which collects a bunch of data and then signs the user up for a newsletter (if requested, of course).  I thought I could call one of the actions in the NMS from a User Defined Tag, but I don't know how to call another module's code.  Is there an easy way to do this?  The NMS has a do_create_new_user action, and if I add the correct params, I think it would just work.

Thanks,
Rorik

Re: Calling code from other modules

Posted: Tue Sep 11, 2007 12:05 am
by aln_cms
Hi,
This isn't my development system, so I don't have access to my code but here goes :

Code: Select all



$modulename = 'FormBuilder';

$cmsmodules = &$gCms->modules;
if (isset($cmsmodules[$modulename]))
{
if (isset($cmsmodules[$modulename]['object'])
	&& $cmsmodules[$modulename]['installed'] == true
	&& $cmsmodules[$modulename]['active'] == true ) {

$result = $cmsmodules[$modulename]['object']->YourFunctionCallHere();

}


This is rough, but it should gt you near.

Re: Calling code from other modules

Posted: Tue Sep 11, 2007 12:25 am
by rmelberg
Thanks, I will give it a shot.

-R

Re: Calling code from other modules

Posted: Wed Sep 12, 2007 2:17 am
by rmelberg
Just for posterity, the code that ended up working in the User Defined Tag was this, very similar to what was suggested, but with a couple of wrinkles, like having to define the global $gCms var and such.  Thanks for your help aln_cms!

//AddUsertoEmailList
//Adds user to Newsletter email list

$email = $params['Email'];
$params['email'] = $email;

$name = $params['Name'];
$params['username'] = $name;

$lists = array(1);
$params['lists'] = $lists;

$modulename = 'NMS';

global $gCms;

$cmsmodules = $gCms->modules;

if (isset($cmsmodules[$modulename]))
{
    $returnid = 0;
    $cmsmodules[$modulename]['object']->DoAction('do_create_new_user','',$params,$returnid);
}

Re: Calling code from other modules

Posted: Wed Sep 12, 2007 4:49 pm
by aln_cms
my pleasure.

Re: Calling code from other modules

Posted: Thu Sep 25, 2008 10:08 pm
by sn3p
I've also made an UDT for this, check it out here.