This documentation page is for Quform version 1 and may not be applicable for Quform 2 click here to visit the documentation for Quform 2.

Step 1

You should first create the list on MailChimp, and configure the fields of your list.

Step 2

Get your MailChimp API key. From the MailChimp dashboard click on your name then go to Account Settings → Extras → API keys. If you don’t have an API key already, click Create a Key to create one.

Step 3

Get your MailChimp List Unique ID. From the MailChimp dashboard click on Lists, go to the list Settings by clicking the arrow at the right hand side of the list, then click on Settings, the Unique ID is at the bottom of the page.

Step 4

Get the MailChimp merge tags for the other fields you want to save. When viewing the list, go the Settings and then List fields and |*MERGE*| tags. What you need is the tag text between the |* and *|.

Step 5

Download the MailChimp API PHP class from here. Extract the files and place the file MCAPI.class.php into your theme directory at wp-content/themes/YOUR_THEME.

Step 6

Get the unique ID of your Quform form, see Finding the form ID.

Step 7

Get the unique ID of your Quform email field, see Finding the unique element ID.

Step 8

If you are saving other data you’ll also need the unique element ID for the other elements you want to save which you can get using the same method as above in Step 7.

Step 9

Add the following code to the wp-content/themes/YOUR_THEME/functions.php file (or create a plugin for it, if you do create a plugin make sure to have the MCAPI.class.php file in the same folder as the plugin file).

1
2
3
4
5
6
78910
11
12
13141516
17
18
19
20
21
22
23
24
25
26
27
function my_save_to_mailchimp($form)
{
    if (!class_exists('MCAPI')) {
        require_once dirname(__FILE__) . '/MCAPI.class.php';
    }
 
    $api = new MCAPI('123456789abcde12345678abcde12345-us4', true);    $listId = '123456789';    $email = $form->getValue('iphorm_3_1'); 
    // OPTIONAL: if you are saving additional fields to MC, set the merge tags, otherwise set $mergeVars to an empty array
    $mergeVars = array(
        'MERGE1' => $form->getValue('iphorm_3_2'),        'MERGE2' => $form->getValue('iphorm_3_3'),        'MERGE3' => $form->getValue('iphorm_3_4')    );
 
    // Other settings
    $emailType = 'html';
    $doubleOptin = false;
    $updateExisting = false;
    $replaceInterests = false;
    $sendWelcome = false;
 
    $api->listSubscribe($listId, $email, $mergeVars, $emailType, $doubleOptin, $updateExisting, $replaceInterests, $sendWelcome);
}
add_action('iphorm_post_process_3', 'my_save_to_mailchimp', 10, 1);
function my_save_to_mailchimp($form)
{
    if (!class_exists('MCAPI')) {
        require_once dirname(__FILE__) . '/MCAPI.class.php';
    }

    $api = new MCAPI('123456789abcde12345678abcde12345-us4', true);
    $listId = '123456789';
    $email = $form->getValue('iphorm_3_1');

    // OPTIONAL: if you are saving additional fields to MC, set the merge tags, otherwise set $mergeVars to an empty array
    $mergeVars = array(
        'MERGE1' => $form->getValue('iphorm_3_2'),
        'MERGE2' => $form->getValue('iphorm_3_3'),
        'MERGE3' => $form->getValue('iphorm_3_4')
    );

    // Other settings
    $emailType = 'html';
    $doubleOptin = false;
    $updateExisting = false;
    $replaceInterests = false;
    $sendWelcome = false;

    $api->listSubscribe($listId, $email, $mergeVars, $emailType, $doubleOptin, $updateExisting, $replaceInterests, $sendWelcome);
}
add_action('iphorm_post_process_3', 'my_save_to_mailchimp', 10, 1);

Modify the highlighted lines to suit your form setup.

  • On line 7, change 123456789abcde12345678abcde12345-us4 to your MailChimp API key, from Step 2
  • On line 8, change 123456789 to your subscriber list unique ID, from Step 3
  • On line 9, change iphorm_3_1 to the unique ID of the email element in your form, from Step 7
  • On line 13, change MERGE1 to the first merge tag you want to set, from Step 4. Repeat for your other merge tags.
  • On line 13, change iphorm_3_2 to the unique Quform element ID of the field you want to save into MERGE1, from Step 8. Repeat for your other merge tags.
  • On line 27, change the number 3 to the unique ID of your Quform form, from Step 6
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy