This guide will show you how to add a new contact to ActiveCampaign when a user submits a Quform form.

Add the following code to the WordPress theme functions.php file (or create a plugin for it).

1234
5
6
7891011
12
13
14
15
16
17
18
19
20
21
22
add_filter('quform_post_process_1', function (array $result, Quform_Form $form) {    $apiUrl = 'https://example.api-us1.com';    $apiKey = 'yourApiKey'; 
    $data = array(
        'contact' => array(
            'email' => $form->getValue('quform_1_4'),            'firstName' => $form->getValue('quform_1_3')[2],            'lastName' => $form->getValue('quform_1_3')[4],            'phone' => $form->getValue('quform_1_5')        )
    );
 
    wp_remote_post($apiUrl . '/api/3/contacts', array(
        'headers' => array(
            'Api-Token' => $apiKey
        ),
        'body' => wp_json_encode($data)
    ));
 
    return $result;
}, 10, 2);
add_filter('quform_post_process_1', function (array $result, Quform_Form $form) {
    $apiUrl = 'https://example.api-us1.com';
    $apiKey = 'yourApiKey';

    $data = array(
        'contact' => array(
            'email' => $form->getValue('quform_1_4'),
            'firstName' => $form->getValue('quform_1_3')[2],
            'lastName' => $form->getValue('quform_1_3')[4],
            'phone' => $form->getValue('quform_1_5')
        )
    );

    wp_remote_post($apiUrl . '/api/3/contacts', array(
        'headers' => array(
            'Api-Token' => $apiKey
        ),
        'body' => wp_json_encode($data)
    ));

    return $result;
}, 10, 2);
  • On line 1, replace the number 1 with the form ID
  • On line 2, replace https://example.api-us1.com with your ActiveCampaign API Access URL (see below)
  • On line 3, replace yourApiKey the ActiveCampaign API Access Key (see below)
  • On line 7, replace 1_4 with the Email element unique ID
  • On lines 8 and 9, replace 1_3 with the Name element unique ID if the form has a Name element, otherwise these lines can be removed
  • On line 10, replace 1_5 with the Phone element unique ID if the form has a Phone element, otherwise this line can be removed

How to get your ActiveCampaign API Access URL & Key

Log in to ActiveCampaign and go to Settings → Developer where you will find the fields containing your ActiveCampaign API Access URL & Key to use in the code above.

Where to find ActiveCampaign API URL and Key

Be inspired. © 2019 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy