Page 1 of 1
[SOLVED] FormBuilder value to UDT/Newsletter Made Simple
Posted: Tue Jun 08, 2010 1:26 am
by webform
I missing something here - But the question is what ???
I'm trying to pass FormBuilder values to an UDT for signing up users to a series of Newsletter list's depending of what they answer in the form (Checkboxes).
I've created a group of checkboxes in FormBuilder with values matching Newsletter list's ID's. Then in the UDT i catch the values and pass to NMS. Users do get added to NMS and to the mandatory list (value 1 in the array) and to the first value in the checkbox group. The problem is every other selected value in the checkbox group gets ignored.
So if an user have selected checkboxes 2 and 5, only checkbox 2 gets added to NMS.
Here i catch the checkbox group in the UDT:
Code: Select all
$list = '';
if (isset($params['list']))
$list = $params['list'];
$newslist = array(1,$list);
Here i push the user to NMS:
Code: Select all
$nms->AddUser($email, $newslist, $name);
If i hardcode the array all is just ok and all 3 is added to NMS:
If i echo $params['list'] i get: "2,5". So why is only 2 then added to NMS?
Re: FormBuilder value to UDT/Newsletter Made Simple
Posted: Tue Jun 08, 2010 10:56 am
by webform
Well i solved it after a good night sleep
I just needed to split the values from the checkbox group into an array. Lesson learned; Don´t work late into the night
Code: Select all
$list = '';
if (isset($params['list']))
$list = $params['list'];
$list_array = explode(",", $list);
$newslist = $list_array;
$newslist[] = 1;
Re: [SOLVED] FormBuilder value to UDT/Newsletter Made Simple
Posted: Tue Jun 08, 2010 11:24 am
by webform
In case others can use this UDT i post it here. (Based on Ted's UDT "FrontEndUsers to NMS (via SelfRegistration)"
http://forum.cmsmadesimple.org/index.php/topic,34004.0.html
Case: A FormBuilder form with a row of questions customers can answer when signing up for a Newsletter. The different Newsletter lists are represented in form of a checkbox group each checkbox with a value matching a NMS list ID. The UDT push the customer into NMS and adding them to different lists depending on their answers.
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');
if ($nms == FALSE)
return false;
if (!isset($params['name']) && !isset($params['email']))
return;
$name = '';
if (isset($params['name']))
$name = $params['name'];
$email = '';
if (isset($params['email']))
$email = $params['email'];
$list = '';
if (isset($params['list']))
$list = $params['list'];
$list_array = explode(",", $list);
$newslist = $list_array;
//This is a mandatory list ID all should belong to
$newslist[] = 1;
//Add user to NMS
$nms->AddUser($email, $newslist, $name);
//Set the confirmed flag to true
$db =& $gCms->GetDb();
$db->Execute('UPDATE ' . cms_db_prefix() . 'module_nms_users SET confirmed = 1 where email = ?', array($email));
Re: [SOLVED] FormBuilder value to UDT/Newsletter Made Simple
Posted: Mon Jan 31, 2011 11:54 pm
by Festarossa
Thank you for this, really needed it.
Though there's a problem I need to solve... At the moment the script I've modified based on one above doesn't recognize the checkbox stating whether user can on cannot be added to NMS list. This is what I have now:
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');
if ($nms == FALSE)
return false;
if (!isset($params['name']) && !isset($params['email']))
return;
$name = '';
if (isset($params['name']))
$name = $params['name'];
$email = '';
if (isset($params['email']))
$email = $params['email'];
$list = '';
if (isset($params['list']))
$list = $params['list'];
$newslist = $list;
//This is a mandatory list ID all should belong to
$newslist[] = 1;
//Add user to NMS
$nms->AddUser($email, $newslist, $name);
//Set the confirmed flag to true
$db =& $gCms->GetDb();
$db->Execute('UPDATE ' . cms_db_prefix() . 'module_nms_users SET confirmed = 1 where email = ?', array($email));
This adds user to NMS list whether the checkbox of permission to do so is checked or not. It would need to recognize if it is checked. Any ideas?
Re: [SOLVED] FormBuilder value to UDT/Newsletter Made Simple
Posted: Tue Feb 01, 2011 9:51 am
by webform
I suppose you use $list for the checkbox?
If so you don't need this or else your always submitting value 1 as list id:
Code: Select all
$newslist = $list;
//This is a mandatory list ID all should belong to
$newslist[] = 1;
Change this
Code: Select all
$nms->AddUser($email, $newslist, $name);
to this
Code: Select all
$nms->AddUser($email, $list, $name);
Maybe you should also check for if the checkbox is empty or not before you submit the code!
Re: [SOLVED] FormBuilder value to UDT/Newsletter Made Simple
Posted: Fri Feb 04, 2011 1:18 am
by Festarossa
Many thanks! This pushed me to right direction, I think.
One question though (I'm sure you already guessed: I'm rather an amateur with php): how do I check whether the checkbox is empty or not? (!isset($params['my_id'])) doesn't seem to work...
Re: [SOLVED] FormBuilder value to UDT/Newsletter Made Simple
Posted: Fri Feb 04, 2011 9:05 am
by webform
Possible you could just extend this line
Code: Select all
if (!isset($params['name']) && !isset($params['email']))
return;
with this line
Code: Select all
if (!isset($params['name']) && !isset($params['email']) && !isset($params['list']))
return;