Description

If you use RSForm!Pro on your website, you can integrate AcyMailing with RSForm!Pro so that when a user submits a form, this user is also subscribed to one or several AcyMailing Lists.

There are three ways to do this. The recommended method is to use php code to add the user after the form is submitted.

 

Integration with RSForm!Pro

Integrate AcyMailing and RSForm!Pro using php code

You can configure RSForm!Pro to execute this php code to subscribe the user to AcyMailing.

This script should go in the Script called after form has been processed area in RSForm!Pro. You can find this area when editing your form, in the property tab, PHP Scripts part.

Don't forget to replace in the following code the name of the email and name fields by the ones of your form as wall as putting the list ID you want to subscribe the users to. See comments in the code below.

Show/Hide php code

View source
$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_field']); //Please replace email_field by your own field name (the name of the field "email").
 $myUser->name = strip_tags($postData['name_field']); //Please replace name_field by your own field name (the name of the field "name").
 $subscriberClass = acymailing_get('class.subscriber');
 
 $subscribe = array(3,4,5); //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;
 }
 }
 $subscriberClass->saveSubscription($subid,$newSubscription);
 

 

You may want to subscribe the user to AcyMailing only if he checks a box to really opt in...
If it's the case, you should call your checkbox "subscribeme" and use this php code:

Show/Hide php code

View source
$postData = JRequest::getVar('form');
if(empty($postData['subscribeme'])) return;
 
 
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_field']); //Please replace email_field by your own field name (the name of the field "email").
 $myUser->name = strip_tags($postData['name_field']); //Please replace name_field by your own field name (the name of the field "name").
 $subscriberClass = acymailing_get('class.subscriber');
 
 $subscribe = array(3,4,5); //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;
 }
 }
 $subscriberClass->saveSubscription($subid,$newSubscription);
 
 
 
 

 

 

Integrate AcyMailing and RSForm!Pro using Curl

Please make sure you successfully tested the subscription via URL before trying to integrate AcyMailing and RSForm!Pro using Curl.

Once you tested your subscription via URL, you want the fields name and e-mail to be automatically replaced by the information sent in the form.

We will explain here a method using the Curl but if your server does not support it or if you want an easier method, you can still use the redirect URL.

Log on to the back-end and click on the menu RSForm!Pro -> Manage Forms.

Select the form you want to integrate with AcyMailing and click on the tab Scripts.

On the area "Script called after form has been processed", copy/paste the following code:

 

Show/Hide php code

View source
$postData = JRequest::getVar('form');
 
 
@ini_set('user_agent', 'My-Application/2.5');
@ini_set('allow_url_fopen', '1');
 
$url = rtrim(JURI::root(),'/').'/index.php?option=com_acymailing&ctrl=sub&task=optin&hiddenlists={hiddenlists}&user[name]={name}&user[email]={email}';
 
$replace = array();
foreach($postData as $id => $oneVal){
 if(is_string($oneVal)) $replace['{'.strtolower($id).'}'] = urlencode($oneVal);
 else $replace['{'.strtolower($id).'}'] = urlencode(implode(',',$oneVal));
}
 
$url = str_replace(array_keys($replace),$replace,$url);
 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, 1);
 
$result = curl_exec($ch);
curl_close($ch);

 

 

RSForm Script

If you use a recent version of RSForm, the script area is under the tab "Properties" when you edit your form:

Script RSForm

This script will require three fields to work properly.

Click on the tab "Components" to add at least these three fields:

    • You should add a field with the name "Name".

Name field

    • The field "Email" should also be added to your form.

Email Field

    • Then the last field which is required to integrate AcyMailing and RSForm!Pro is the field "hiddenlists".
      The value of this field will be the IDs of the lists you want the user to be subscribed to.
      On our example we added it as an hidden field with the value "1,4" so the user will be subscribed to the lists with ID 1 and 4.

Hiddenlists

 

Integrate AcyMailing and RSForm!Pro using the redirect URL

Please make sure you successfully tested the subscription via URL before trying to integrate AcyMailing and RSForm!Pro using the redirect URL.

Once you tested your subscription via URL, you want the fields name and e-mail to be automatically replaced by the information sent in the form.

You can use the CURL system OR the redirect URL, but don't use both solutions!

Log on to the back-end and click on the menu RSForm!Pro -> Manage Forms.

Edit the form you want to integrate with AcyMailing and select the tab "Edit Form".

 

Redirect url

 

Specify the Return URL:
index.php?option=com_acymailing&ctrl=sub&task=optin&hiddenlists=1,4&user[name]={Name:value}&user[email]={Email:value}

You have to add the values related to your form fields name (so the one specified on the Quick Add tool).

In the url, the parameter hiddenlists=1,4 should be modified by your own lists IDs.

Save the form.

Test this form on your front-end and make sure the user is added and subscribed properly to AcyMailing.

Then, you can add a redirect link to the AcyMailing subscription url so that the user will be redirected to your own thank you page.

Example : index.php?option=com_acymailing&ctrl=sub&task=optin&hiddenlists=1,4&user[email]={Email:value}&user[name]={Name:value}&redirect=http://www.google.fr

Follow us :