# ChronoForm and AcyMailing

## Description <a href="#description" id="description"></a>

If you use ChronoForm on your website, you can integrate AcyMailing with ChronoForm 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 ChronoForm <a href="#integration-with-chronoform" id="integration-with-chronoform"></a>

### Integrate AcyMailing and ChronoForm using a PHP script <a href="#integrate-acymailing-and-chronoform-using-a-php-script" id="integrate-acymailing-and-chronoform-using-a-php-script"></a>

You can configure ChronoForm to execute this php code to subscribe the user to AcyMailing.

Don't forget to replace email\_field and name\_field by your own fields name and to enter the IDs of your lists instead of 3,4,5

```
 <?php  
 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(JRequest::getString('email_field')); //Please replace email_field by your own field name (the name of the field "email"). 
 $myUser->name = strip_tags(JRequest::getString('name_field')); //Please replace name_field by your own field name (the name of the field "name"). 
 $subscriberClass = acymailing_get('class.subscriber'); 
 $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. 
 $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. 
 $newSubscription = array(); 
 if(!empty($subscribe)){ 
 foreach($subscribe as $listId){ 
 $newList = array(); 
 $newList['status'] = 1; 
 $newSubscription[$listId] = $newList; 
 } 
 } 
 $subscriberClass->saveSubscription($subid,$newSubscription);
 ?> 
```

![](/files/-MJWC_CRL1QzHbDsXm8d)

Chronoform step 1

![](/files/-MJWCboMPwxara6ii3N0)

Chronoform step 2

![](/files/-MJWCeC0iq0g6W48V5q8)

Chronoform step 3

![](/files/-MJWCg_pBE11DecNZVov)

Chronoform step 4

### Integrate AcyMailing and ChronoForm using Curl <a href="#integrate-acymailing-and-chronoform-using-curl" id="integrate-acymailing-and-chronoform-using-curl"></a>

​[Please make sure you successfully tested the subscription via URL before trying to integrate AcyMailing and ChronoForm.](/old/developers/subscription-via-url.md#test-the-subscription-via-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.

We recommend you to use the Curl method to do that but if your server does not support it, you can still use the redirect URL.

Log on to the back-end and click on the menu **Chrono Forms -> Forms Management.**

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

![](/files/-MJWCjDA9y_FzF8GTpV9)

ChronoForm Curl

Click on the tab **CURL params** and enter the Target URL : **<http://www.yourwebsite.com/index.php?option=com\\_acymailing>**

Don't forget to replace [www.yourwebsite.com](http://www.yourwebsite.com) by the url of your own website!

![](/files/-MJWClxJ58N_CGv-YklH)

Curl Params

* Click on the tab **General** and enter the AcyMailing equivalent for each field you want to send to AcyMailing.
* Please enter **user\[email]** for the field **email**.
* Please enter **user\[name]** for the field **name**.
* In the area **Extra fields Data**, please enter the text:

**ctrl=sub task=optin hiddenlists=1,4**

(replace **hiddenlists=1,4** by the lists ID you want your user to be subscribed to)

![](/files/-MJWCoUPj7RI_p-mEXw3)

Curl General

Save the CURL plugin.

You should now enable this CURL plugin for your form.

> * Edit your form
> * Click on the tab **Plugins**
> * Click on the CURL plugin to enable it (it should be green to be activated)

![](/files/-MJWCr-LI8yuEzWf0AXm)

CURL enable

You can now test from the front-end. If you have any problem, please turn ON the CURL debug mode (in the tab **CURL params**) so you will see some debug traces when you submit your form.

#### Curl method with ChronoForm v4 <a href="#curl-method-with-chronoform-v4" id="curl-method-with-chronoform-v4"></a>

With Chronoform 4, the subscription via curl will look like that:

![](/files/-MJWCtWAmROTcnOwyMAH)

ChronoForm v4

* You should replace {name} and {email} by your own field value from ChronoForm but leave the user\[name] and user\[email] intact.

### Integrate AcyMailing and ChronoForm using the redirect URL <a href="#integrate-acymailing-and-chronoform-using-the-redirect-url" id="integrate-acymailing-and-chronoform-using-the-redirect-url"></a>

​[Please make sure you successfully tested the subscription via URL before trying to integrate AcyMailing and ChronoForm.](/old/developers/subscription-via-url.md#test-the-subscription-via-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 plugin OR the redirect URL, but don't use both solutions! You might want to use the redirect URL in case the PHP Curl function is not enabled on your website.

Log on to the back-end and click on the menu **Chrono Forms -> Forms Management.**

Edit the form you want to integrate with AcyMailing (click on its name).

Click on the tab **Form Code** and add this code in the area **On Submit code - after sending email :**

```
<?php
$email = urlencode(JRequest::getString('item_1', '', 'post'));
$name = urlencode(JRequest::getString('item_2', '', 'post'));
$MyForm->formrow->redirecturl = JURI::base()."index.php?option=com_acymailing&ctrl=sub&task=optin&hiddenlists=1,4&user[email]=$email&user[name]=$name";
?>
```

In our example we kept the default field names but you might have to change **item\_1** and **item\_2** by **your own field names** (based on what you wrote in the Form Wizard).

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

![](/files/-MJWCwIfpBWFBs02Ld-h)

ChronoForm Code

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 : $MyForm->formrow->redirecturl = JURI::base()."index.php?option=com\_acymailing\&ctrl=sub\&task=optin\&hiddenlists=1,4\&user\[email]=$email\&user\[name]=$nam&#x65;**\&redirect=<http://www.google.fr>**";*

If you want to reach an external website, you should write your complete url and don't use JURI:base():

*Example : $MyForm->formrow->redirecturl = "<http://www.myotherwebsite.com/index.php?option=com\\_acymailing\\&ctrl=sub\\&task=optin\\&hiddenlists=1,4\\&user\\[email]=$email\\&user\\[name]=$nam&#x65;**\\&redirect=http://www.google.fr>\*\*";*


---

# 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/old/developers/subscription-via-url/chronoform-and-acymailing.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.
