Step 1
Download the Aweber PHP API from https://github.com/aweber/AWeber-API-PHP-Library. Click the
button to download.
Step 2
Extract the .zip file and there will be a folder name aweber_api, move this to your theme directory so that it resides at: wp-content/themes/YOUR_THEME/aweber_api/
Step 3
Get your Aweber API credentials and other information, consult the Aweber help for how to find this information. You will need:
- Consumer key – set the $consumerKey variable in the code below to this
- Consumer secret – set the $consumerSecret variable in the code below to this
- Access key – set the $accessKey variable in the code below to this
- Access secret – set the $accessSecret variable in the code below to this
- Account ID – set the $account_id variable in the code below to this
- List ID – set the $list_id variable in the code below to this
- The names of any custom fields from your list that you want to save data to (optional)
Step 4
Get the unique ID of your form, see Finding the form ID.
Step 5
Get the unique ID of your Quform email field, see Finding the unique element ID. Repeat this step for all form fields that you want to save to Aweber. You will need the unique ID of all of them.
Step 6
Open the functions.php file of your theme wp-content/themes/YOUR_THEME/functions.php. At the bottom of this file, add the code below.
12 3 4 5 6 78910111213 14 15 16 17 18 19 20 21 22 2324 2526 272829 30 31 32 33 34 | add_action('iphorm_post_process_3', 'mytheme_save_to_aweber', 10, 1); function mytheme_save_to_aweber($form) { require_once('aweber_api/aweber_api.php'); $consumerKey = '***'; # put your credentials here $consumerSecret = '***'; # put your credentials here $accessKey = '***'; # put your credentials here $accessSecret = '***'; # put your credentials here $account_id = '***'; # put the Account id here $list_id = '***'; # put the List id here $aweber = new AWeberAPI($consumerKey, $consumerSecret); try { $account = $aweber->getAccount($accessKey, $accessSecret); $listURL = "/accounts/{$account_id}/lists/{$list_id}"; $list = $account->loadFromUrl($listURL); # create a subscriber $params = array( 'email' => $form->getValue('iphorm_3_2'), 'ip_address' => $_SERVER['REMOTE_ADDR'], 'name' => $form->getValue('iphorm_3_3'), 'custom_fields' => array( 'Custom field 1' => $form->getValue('iphorm_3_4'), 'Custom field 2' => $form->getValue('iphorm_3_5'), ), ); $subscribers = $list->subscribers; $new_subscriber = $subscribers->create($params); } catch(AWeberAPIException $exc) {} } |
add_action('iphorm_post_process_3', 'mytheme_save_to_aweber', 10, 1);
function mytheme_save_to_aweber($form)
{
require_once('aweber_api/aweber_api.php');
$consumerKey = '***'; # put your credentials here
$consumerSecret = '***'; # put your credentials here
$accessKey = '***'; # put your credentials here
$accessSecret = '***'; # put your credentials here
$account_id = '***'; # put the Account id here
$list_id = '***'; # put the List id here
$aweber = new AWeberAPI($consumerKey, $consumerSecret);
try {
$account = $aweber->getAccount($accessKey, $accessSecret);
$listURL = "/accounts/{$account_id}/lists/{$list_id}";
$list = $account->loadFromUrl($listURL);
# create a subscriber
$params = array(
'email' => $form->getValue('iphorm_3_2'),
'ip_address' => $_SERVER['REMOTE_ADDR'],
'name' => $form->getValue('iphorm_3_3'),
'custom_fields' => array(
'Custom field 1' => $form->getValue('iphorm_3_4'),
'Custom field 2' => $form->getValue('iphorm_3_5'),
),
);
$subscribers = $list->subscribers;
$new_subscriber = $subscribers->create($params);
} catch(AWeberAPIException $exc) {}
}Modify the highlighted lines to suit your setup:
- On line 1, change the number
3to the unique ID of your form, from Step 4 - On lines 7-12, change all the
***to each of your Aweber settings described in Step 3 - On line 23, change
iphorm_3_2to the unique ID of the email element in your form, from Step 5 - On line 25, change
iphorm_3_3to the unique ID of the name element in your form, from Step 5. If you don’t have a name element you should delete the line - On line 27, change
Custom field 1to the name of your first Custom field at Aweber. Repeat this on the lines below for each custom field, adding more lines if required. - On line 27, change
iphorm_3_4to the unique Quform element ID of the field you want to save into ‘Custom field 1′ (or whatever the name of your custom field). Repeat for your other custom fields.
