RSForm!Pro integration

Description

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

Integrate using PHP code

You can configure RSForm!Pro to execute a php script to subscribe the user in AcyMailing. First of all, edit your form and go in the PHP Scripts section:
The script should go in the Script called after form has been processed area to ensure the user isn't subscribed if an error occurs on the form:
You can use this script as a base, and modify it to meet your needs:
1
// Load the AcyMailing library
2
$postData = $_REQUEST['form'];
3
$ds = DIRECTORY_SEPARATOR;
4
include_once rtrim(JPATH_ADMINISTRATOR, $ds).$ds.'components'.$ds.'com_acym'.$ds.'helpers'.$ds.'helper.php';
5
$userClass = new AcyMailing\Classes\UserClass();
6
7
// Build the user based on your form's fields
8
$myUser = new stdClass();
9
$myUser->email = strip_tags($postData['EMAIL_FIELD']);
10
$myUser->name = strip_tags($postData['NAME_FIELD']);
11
12
// If the user already exists update it
13
$existingUser = $userClass->getOneByEmail($postData['EMAIL_FIELD']);
14
if (!empty($existingUser)) $myUser->id = $existingUser->id;
15
16
// You can add as many extra fields as you want if you already created them in AcyMailing
17
$customFields = [];
18
$customFields[CUSTOM_FIELD_ID] = $postData['MY_FIELD']; // the custom field id can be found in the Custom fields list of the AcyMailing admin page
19
20
21
$userClass->sendConf = true; // Or false if you don't want a confirmation email to be sent
22
$userId = $userClass->save($myUser, $customFields);
23
24
25
// The user now exists in AcyMailing, let's add some list subscriptions
26
$subscribe = [2,5,6]; // Ids of the lists you want the user to be subscribed to need to be added in this array
27
$userClass->subscribe($userId, $subscribe);
Copied!
In this code, CUSTOM_FIELD_ID is the ID that can be seen in the Acy custom fields listing.
EMAIL_FIELD, NAME_FIELD and MY_FIELD must be replaced by your form's field names, so in this example it would be "Email", "the user name" and "Our newsletters field name":

Let users choose their subscription

You can add a Radio Group field or a Checkbox Group field to let users choose their subscription. Here are some examples:

Use a Radio Group field as a Yes/No subscription field

1
// The user now exists in AcyMailing, let's add some list subscriptions
2
3
if (!empty($postData['newsletters']) && $postData['newsletters'] === 'Yes') {
4
$subscribe = [2,5,6]; // Ids of the lists you want the user to be subscribed to need to be added in this array
5
$userClass->subscribe($userId, $subscribe);
6
}
Copied!

Use a Checkbox field to choose the lists individually

1
// The user now exists in AcyMailing, let's add some list subscriptions
2
3
$subscribe = [];
4
5
if (!empty($postData['lists'])) {
6
if (in_array('Monthly news', $postData['lists'])) $subscribe[] = 2; // 2 being the list ID corresponding to the monthly news
7
if (in_array('Weekly news', $postData['lists'])) $subscribe[] = 5;
8
if (in_array('Daily news', $postData['lists'])) $subscribe[] = 6;
9
10
$userClass->subscribe($userId, $subscribe);
11
}
Copied!