×

info

Dear guests,
You are currently on the old forum we kept as a knowledge base. You will find the new community forum here
Welcome, Guest
Username: Password: Remember me
Keyword

TOPIC: ACYMailing and RSForm Pro integration

ACYMailing and RSForm Pro integration 3 years 8 months ago #106232

  • Anonymous user
  • nagate816's Avatar
  • Posts: 10
  • Karma: 0
Hello,

I am trying to provide a function that my client has seen in Constant Contact whereby when a site visitor fills in a form they are automatically added to a mailing list IF they are not already in ACYMailing. You provided the first part here: www.acyba.com/acymailing/127-acymailing-rsformpro.html and it seems to work well but it adds the user evn if they are already in ACY, is there a way to have it check if the email address exists in ACY and then only add it when it does not ?

thanks,

Neil A
Please log in to post a reply

ACYMailing and RSForm Pro integration 3 years 8 months ago #106271

  • Tom
  • Tom's Avatar
  • Posts: 4581
  • Karma: 188
Hello,

Just to be sure, if the user is already exists in AcyMailing, you don't want to change his subscription when he fills the RSForm Pro form?
In this case, you can use our API to try to modify your script and try to get the user from AcyMailing using the email address: www.acyba.com/acymailing/64-acymailing-d....html#api_getusersub
(you don't need the last part "get user subscription", only try to get his subscriber ID).

If the user doesn't exists in AcyMailing, then you subscribe him.
Please log in to post a reply

ACYMailing and RSForm Pro integration 3 years 8 months ago #106311

  • Anonymous user
  • nagate816's Avatar
  • Posts: 10
  • Karma: 0
Hello Tom,

Thank you for your reply. I am struggling with this and wonder if you can look at the following. My logic is that is the value for $subid does not exist then I want to execute the code to add the user/email to ACY. I am not sure if my logic is wrong or my syntax. Here is what I am using:
$postData = JRequest::getVar('form');

include_once(rtrim(JPATH_ADMINISTRATOR,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_acymailing'.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'helper.php');

$myUser = new stdClass();
$myUser->email = strip_tags($postData['Email']); //Please replace email_field by your own field name (the name of the field "email").
$myUser->name = strip_tags($postData['Name']); //Please replace name_field by your own field name (the name of the field "name").
$subscriberClass = acymailing_get('class.subscriber');

$subscribe = array(3,16); //Specify here the ID of your lists separated by a comma, in this example the user will be subscribed to lists IDs 3,4 and 5.
$_REQUEST['subscription'] = $subscribe; //Only useful when using a subscription condition in the "Create Joomla user" plugin, you can delete this line if you don't use this plugin

$subid = $subscriberClass->save($myUser);


$subscriberClass->sendConf($subid); //we send the confirmation email... only if needed based on the current user status and the option from the Acy configuration page.

$newSubscription = array();
if(!empty($subscribe)){
foreach($subscribe as $listId){
$newList = array();
$newList['status'] = 1;
$newSubscription[$listId] = $newList;
}
}

// Get the subscriber ID (ID of the AcyMailing user) from his email address or his Joomla user ID
$userClass = acymailing_get('class.subscriber');
$subid = $userClass->subid($emailOrUserID);

if ( $subid = "" ) {
     $subscriberClass->saveSubscription($subid,$newSubscription);
}

Thank you for any assistance you can provide,

Neil A.
Last Edit: 3 years 8 months ago by Tom.
Please log in to post a reply

ACYMailing and RSForm Pro integration 3 years 8 months ago #106341

  • Tom
  • Tom's Avatar
  • Posts: 4581
  • Karma: 188
Hello,

The issue is you are first creating the user and then checking if he exists. So with this script you will always have a user.
You should check if the user exists before saving him (the save function create the user).
You should also use the email you get from your form to check if the user exists: replace $emailOrUserID by the email you got.
Here is a modified version of your code with some improvements (not tested). Basically I get information from the form, and check if the user exists in AcyMailing. If he already exists I don't do anything, if not I create and subscribe him:
$postData = JRequest::getVar('form');

include_once(rtrim(JPATH_ADMINISTRATOR,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_acymailing'.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'helper.php');

$myUser = new stdClass();
$myUser->email = strip_tags($postData['Email']); //Please replace email_field by your own field name (the name of the field "email").
$myUser->name = strip_tags($postData['Name']); //Please replace name_field by your own field name (the name of the field "name").
$subscriberClass = acymailing_get('class.subscriber');

// Get the subscriber ID (ID of the AcyMailing user) from his email address or his Joomla user ID
$subid = $subscriberClass->subid($myUser->email);
if(empty($subid)){
	$subscribe = array(3,16); //Specify here the ID of your lists separated by a comma, in this example the user will be subscribed to lists IDs 3,4 and 5.
	// Create user
	$subid = $subscriberClass->save($myUser);

	$subscriberClass->sendConf($subid); //we send the confirmation email... only if needed based on the current user status and the option from the Acy configuration page.

	$newSubscription = array();
	if(!empty($subscribe)){
		foreach($subscribe as $listId){
			$newList = array();
			$newList['status'] = 1;
			$newSubscription[$listId] = $newList;
		}
	}
	$subscriberClass->saveSubscription($subid, $newSubscription);
}
Please log in to post a reply
Time to create page: 0.072 seconds
Powered by Kunena Forum