CF7 Custom Fields not going to Mailchimp
-
I need assistance with Mailchimp for WordPress (mc4wp) plugin integration with Contact Form 7
Dear Mailchimp for WordPress (mc4wp) Support Team,
Problem Description:
I have set up a Contact Form 7 form on my website to capture user subscriptions and send the form data to my Mailchimp list using the mc4wp plugin. However, despite the form being submitted successfully, and email/name data successfully being passed to Mailchimp, the custom field (unique-link, in this case) is not being sent to Mailchimp. The custom field data is even being stored in the Flamingo plugin (a Contact Form 7 add-on), but the data is not reaching my Mailchimp list.I’ve refreshed the list and made sure the custom field name matches the field name in Mailchimp exactly.
It may have to do with a quirky interaction of mc4wp with the script I’m running. I say it’s a quirk with mc4wp because again, Flamingo reads the form data just fine.
- I have created a custom function to generate a unique link for each subscriber based on their email address. The unique link is generated using a secret key, expiration time, and a hash function. Here’s the code snippet for the link generation (italics = redacted for privacy)
function generate_secure_link($email) { $secret_key = 'mykey'; $expiration_time = time() + (3 * 24 * 60 * 60); // 3 days from now $data = $email . '|' . $expiration_time; $hash = hash_hmac('sha256', $data, $secret_key); $base_url = "http://mydomain.com/link-validation"; $link = $base_url . "?data=" . urlencode(base64_encode($data)) . "&hash=" . $hash; return $link; }
2. I have created a function to add the generated unique link to the Contact Form 7 form data using the
wpcf7_posted_data
filter. Here’s the code snippet:function add_unique_link_to_cf7_data($posted_data) { $email = $posted_data['your-email']; $unique_link = generate_secure_link($email); $posted_data['unique-link'] = $unique_link; return $posted_data; } add_filter('wpcf7_posted_data', 'add_unique_link_to_cf7_data');
3. I have created a function to retrieve the unique link value for the Dynamic Text Extension in Contact Form 7. Here’s the code snippet:
function CF7_get_custom_field($atts) { $key = 'unique-link'; $value = ''; if (isset($_POST[$key])) { $value = $_POST[$key]; } return $value; }
4. My Contact Form 7 form includes the necessary fields (name and email) and the hidden input field for the unique link. Here’s the form configuration:
<label> Your Name (required) [text* your-name akismet:author autocomplete:name] </label> <label> Your Email (required) [email* your-email akismet:author_email autocomplete:email] </label> [dynamichidden unique-link "CF7_get_custom_field key='unique-link'"] [mc4wp_checkbox] [submit "Subscribe"] [response]
The form submissions are successful, and the data is being captured by the Flamingo plugin, but it seems that the integration with mc4wp is not functioning as expected.
Since the issue appears to be related to the mc4wp plugin integration, I believe your expertise would be more suitable to help resolve this problem.
Additional Information:
- WordPress version: 6.5.2
- Contact Form 7 version: 5.9.3 (updated today)
- Mailchimp for WordPress (mc4wp) version: 4.9.11 (updated today)
- PHP version: 7.4.33 (Supports 64bit values)
FWIW I spent many hours trying to troubleshoot this, so I thank you in advance for your help and support.
Best regards,
DataLife
- The topic ‘CF7 Custom Fields not going to Mailchimp’ is closed to new replies.