# 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:

![](/files/-MRP72BiYsHvjyPbittf)

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:

![](/files/-MRP7IRhkYYjN4KxXgog)

You can use this script as a base, and modify it to meet your needs:

{% code lineNumbers="true" %}

```php
// Load the AcyMailing library
$postData = $_REQUEST['form'];
$ds = DIRECTORY_SEPARATOR;
include_once rtrim(JPATH_ADMINISTRATOR, $ds).$ds.'components'.$ds.'com_acym'.$ds.'Core'.$ds.'init.php';
$userClass = new AcyMailing\Classes\UserClass();

// Build the user based on your form's fields
$myUser = new stdClass(); 
$myUser->email = strip_tags($postData['EMAIL_FIELD']);
$myUser->name = strip_tags($postData['NAME_FIELD']);

// If the user already exists update it
$existingUser = $userClass->getOneByEmail($postData['EMAIL_FIELD']);
if (!empty($existingUser)) $myUser->id = $existingUser->id;

// You can add as many extra fields as you want if you already created them in AcyMailing
$customFields = [];
$customFields[CUSTOM_FIELD_ID] = $postData['MY_FIELD']; // the custom field id can be found in the Custom fields list of the AcyMailing admin page


$userClass->sendConf = true; // Or false if you don't want a confirmation email to be sent
$userId = $userClass->save($myUser, $customFields);


// The user now exists in AcyMailing, let's add some list subscriptions
$subscribe = [2,5,6]; // Ids of the lists you want the user to be subscribed to need to be added in this array
$userClass->subscribe($userId, $subscribe);
```

{% endcode %}

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":

![](/files/-MRPDthSuaKWFC0q_iHa)

### 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

![](/files/-MRPF5pt3AIu1x81QGpi)

{% code lineNumbers="true" %}

```php
// The user now exists in AcyMailing, let's add some list subscriptions

if (!empty($postData['newsletters']) && $postData['newsletters'] === 'Yes') {
    $subscribe = [2,5,6]; // Ids of the lists you want the user to be subscribed to need to be added in this array
    $userClass->subscribe($userId, $subscribe);
}
```

{% endcode %}

### Use a Checkbox field to choose the lists individually

![](/files/-MRPG1G6zev_17OF-yaZ)

{% code lineNumbers="true" %}

```php
// The user now exists in AcyMailing, let's add some list subscriptions

$subscribe = [];

if (!empty($postData['lists'])) {
    if (in_array('Monthly news', $postData['lists'])) $subscribe[] = 2; // 2 being the list ID corresponding to the monthly news
    if (in_array('Weekly news', $postData['lists'])) $subscribe[] = 5;
    if (in_array('Daily news', $postData['lists'])) $subscribe[] = 6;
    
    $userClass->subscribe($userId, $subscribe);
}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.acymailing.com/setup/subscription-to-your-lists/rsform-pro-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
