Published on
Here's a little tutorial in cURL with AcyMailing. This one is updated to use ChonoForms v4 and AcyMailing 3.5.0 on Joomla! 2.5
Analysing the AcyMailing module to find the parameters is uses
We'll start with the HTML from the AcyMailing module as this tells us what needs to be submitted. Here is is with all the non-essential code removed:
<form name="formAcymailing1" method="post" action="/Joomla2.5a/index.php" > <input type="checkbox" value="1" name="subscription[]" > <input type="checkbox" value="3" name="subscription[]" > <input type="text" value="Name" name="user[name]" > <input type="text" value="E-mail" name="user[email]" > <input type="submit" name="Submit" value="Subscribe" > <input type="hidden" value="0" name="ajax"> <input type="hidden" value="sub" name="ctrl"> <input type="hidden" value="notask" name="task"> <input type="hidden" value="http%3A%2F%2Fmy_site.com" name="redirect"> <input type="hidden" value="http%3A%2F%2Fmy_site.com" name="redirectunsub"> <input type="hidden" value="com_acymailing" name="option"> <input type="hidden" value="2,4" name="hiddenlists"> <input type="hidden" value="formAcymailing1" name="acyformname"> </form>
We can strip this down even further to a series of name/value pairs that we may need to pass to AcyMailing:
Submit=Subscribe ajax=0 ctrl=sub task=notask redirect=http%3A%2F%2Fmy_site.com redirectunsub=http%3A%2F%2Fmy_site.com option=com_acymailing hiddenlists=2,4 acyformname=formAcymailing1 subscription[]=1,3 user[name]=Name user[email]=E-mail
We probably don't need to send Submit, ajax, redirect, redirectunsub and acyformname so we'll leave those out for the moment. The subscription[] and user[name] + user[email] parameters will come from user inputs and the remaining values will have static values that are the same every time the form is submitted.
One last piece of information from the module is that the url to submit the information to is just 'index.php' (the rest is included in the parameters).
Creating the subscription actions in ChronoForms
We want to send the just the data to AcyMailing without sending the user there. There are several ways to so this* but we'll use cURL after the form is submitted.
We could use the standard CURL action but it has doesn't accept static values** so it's simpler to use my cURL [GH] custom action (get it {rokbox text=|here| size=|1000,600| }http://greyhead.net/how-to-docs/cfv4-curl-gh-action{/rokbox} and use the Action Installer icon in the ChronoForms toolbar to install it.)
Open the Action to configure it.
The Target URL is just index.php or http://example.com/index.php if you prefer.
The cURL [GH] action takes both 'dynamic' data from the form as name={input_name} and 'static' data as name=value so we can add ur name value pairs like this:
ctrl=sub
task=optin
option=com_acymailing
hiddenlists=2,4
subscription={subscription}
user[name]={name}
user[email]={email}
Important: Although the AcyMailing module shows task=notask this will not work for the ChronoForm, it needs to be changed to task=optin
If you don't have any 'fixed' lists that you want everyone to subscribe to the leave out hiddenlists.
Save the Form and testConverting form options into AcyMailing list subscriptions
If you have several AcyMailing lists you may want to slect lists depending on the options the user selects in the form. Here we assume that the form has a drop-down select for 'interests'.
There are two ways to convert the options into lists. The easiest is just to set the option values to the list ids and name the select box 'subscription' :
3=Fashion Event 4=Themed Event 5=Music Event 6=Movie Event 7=Golf Event 8=Charity Event 9=Commodities 1=Other
The second more complicated route is to use a Custom code action to map from one to the other - this gives you more flexibility.
You can keep the options as
Fashion=Fashion Event Themed=Themed Event Music=Music Event Movie=Movie Event Golf=Golf Event Charity=Charity Event Commodities=Commodities Other=Other
and then use a Custom Code box like this (I'm assuming that the drop-down name is 'event_interests')
<?php
$list_map = array (
'Fashion' => '2',
'Themed' => '3',
'Music' => '4',
'Movie' => '5',
'Golf' => '9',
'Charity' => '9',
'Commodities' => '3',
'Other' => '9'
);
$subscriptions = array();
foreach ( $form->data['event_interests'] as $d ) {
$subscriptions[] = $list_map[$d];
}
// remove duplicate entries
$form->data['subscriptions'] = array_unique($subscriptions);
?>
the cURL [GH] Params/Fields Map is then:
ctrl=sub
task=optin
option=com_acymailing
subscription={subscription}
user[name]={name}
user[email]={email}
* Others are to build Ajax into the form or to use an HTTP request just before the form is submitted. I prefer cURL as the simplest way to do the job.
** You can get round this by setting the values in hidden inputs, or in a Custom Code action before the cURL action - just a bit messy.

Comments: