• Resolved DataLife

    (@antibalashifi)


    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.

    1. 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 = "https://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

    • This topic was modified 7 months, 1 week ago by DataLife.
Viewing 15 replies - 1 through 15 (of 24 total)
  • Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hello,

    Please check this.

    In order for our plugin to detect which field data to send to MC (other than name & email), you will need to prefix the field name with “mc4wp-“.

    Thread Starter DataLife

    (@antibalashifi)

    Thank you for your guidance on prefixing the custom field name with “mc4wp-” to send the data to Mailchimp.

    However, after making the changes, the unique link is still not being sent to Mailchimp along with the form data.

    I have implemented the following changes:

    1. Updated the PHP code to use the prefixed field name “mc4wp-unique-link”.
    2. Updated the Contact Form 7 form configuration to use the prefixed field name.
    3. Ensured that a corresponding custom field with the same prefixed name exists in my Mailchimp list.
    4. did “Refresh List” in mc4wp settings.

    I switched the relevant CF7 form function to DYFCF7_get_custom_field So currently it looks like this:

    <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 mc4wp-unique-link "DYFCF7_get_custom_field key='mc4wp-unique-link'"]
    
    [mc4wp_checkbox]
    
    [submit "Subscribe"]
    
    [response]

    I also updated the PHP to match and it’s genering the hash just fine (it’s stored in Flamingo)

    I also chatted with Mailchimp API support and they said that “it seems like the unique link field is being sent over, but it’s showing blank. Where is that field’s data coming from.”

    So maybe mc4wp is sending data to Mailchimp before it’s being added to the CF7 data?

    Could you please provide further assistance in troubleshooting this issue?

    I appreciate your support.

    Edit: also you didn’t mention that while the field name on the form should be mc4wp-unique-link, it should remain unique-link on Mailchimp aka NOT MATCHING. Took me awhile to figure it out. Can you make sure this part is right?

    [dynamichidden mc4wp-unique-link "DYFCF7_get_custom_field key='mc4wp-unique-link'"]

    Best regards,
    Data

    • This reply was modified 7 months, 1 week ago by DataLife.
    • This reply was modified 7 months, 1 week ago by DataLife.
    • This reply was modified 7 months, 1 week ago by DataLife.
    • This reply was modified 7 months, 1 week ago by DataLife.
    • This reply was modified 7 months, 1 week ago by DataLife.
    • This reply was modified 7 months, 1 week ago by DataLife.
    Thread Starter DataLife

    (@antibalashifi)

    Or can I just skip using Dynamic Text Field and use this for CF7:

    [hidden mc4wp-unique-link]

    with

    // Add unique link to Contact Form 7 form data
    function add_unique_link_to_cf7_data($form_data) {
      $email = $form_data['your-email'];
      $unique_link = generate_secure_link($email);
      $form_data['mc4wp-unique-link'] = $unique_link;
      return $form_data;
    }
    add_filter('wpcf7_posted_data', 'add_unique_link_to_cf7_data');

    or should we use this

    // mc4wp_form_data method
    function add_unique_link_to_cf7_data($form_data, $form_id) {
      if (isset($form_data['EMAIL'])) {
        $email = $form_data['EMAIL'];
        $unique_link = generate_secure_link($email);
        $form_data['UNIQUELINK'] = $unique_link;
      }
      return $form_data;
    }
    add_filter('mc4wp_form_data', 'add_unique_link_to_cf7_data', 10, 2);
    Plugin Contributor Lap

    (@lapzor)

    A hidden field should work.

    The mc4wp- prefix isn’t always needed, but in cases where the plugin doesn’t pick up the field automatically it can help.

    Also make sure that the plugin knows about the field on Mailchimp, is the field was just recently created the plugin might not yet be aware of it and not send the data to Mailchimp. TO make sure, go to MC4WP > Mailchimp, and then click “Renew Mailchimp lists”. Then you can click on the list name to fold it open and see all the field names.

    Can you share a link to where I can see the form on your site if it’s still not working?

    Thanks for letting me know.

    Thread Starter DataLife

    (@antibalashifi)

    “Renew Mailchimp lists”.

    This is actually what I meant by

    I did “Refresh List” in mc4wp settings.

    On the page “Mailchimp for WordPress: API Settings,” the text field unique-link appears, with UNIQUELINK as the merge tag.

    (And it’s been that way for over a day now, and I’m not using any caching plugins at the moment, so I think it should be “propagated” by now, which I guess could be a thing according to another support post I saw.)

    It’s on this page:

    https://shaina.link/deleteme

    I’d love to know your thoughts!

    • This reply was modified 7 months, 1 week ago by DataLife.
    Plugin Contributor Lap

    (@lapzor)

    Hi,

    I checked the link where I can see the form and noticed that the field is there in the form (hidden), but the value of the field is not set. So the problem might be with the add_unique_link_to_cf7_data function code.

    Thread Starter DataLife

    (@antibalashifi)

    Hi,

    I debugged using

    // Add unique link to Contact Form 7 form data
    function add_unique_link_to_cf7_data($form_data) {
      if (isset($form_data['your-email'])) {
        $email = $form_data['your-email'];
        $unique_link = generate_secure_link($email);
        $form_data['mc4wp-unique-link'] = $unique_link;
        
        // Log debug messages
        error_log('Generated Unique Link: ' . $unique_link);
        error_log('Form Data: ' . print_r($form_data, true));
      } else {
        // Log debug message
        error_log('Email field not found in form data');
      }
      return $form_data;
    }

    And what returned all looked 100% correct. This coincides with what is being logged in Flamingo, which looks 100% correct. Mailchimp is still not seeing the custom field however.

    Hmm.

    Nathan

    debug log: https://safenote.co/r/66243a99d8f9e2@29000988

    • This reply was modified 7 months, 1 week ago by DataLife.
    • This reply was modified 7 months, 1 week ago by DataLife.
    Plugin Contributor Lap

    (@lapzor)

    Just checked again. No value shows in the form when I insect the code: https://imgur.com/a/9DDLjA2

    Thread Starter DataLife

    (@antibalashifi)

    Thanks for your continued support ??

    Okay so I was trying to generate the hash after submission, and I realized it’s easier to create the hash on page load, and put it in the hidden form field, so now you can see it in Inspect. However it’s still not populating that field in Mailchimp. I tried with and without the mc4wp- prefix.

    • This reply was modified 7 months, 1 week ago by DataLife.
    Plugin Contributor Lap

    (@lapzor)

    When I test it myself I can’t see any value on the hidden field yet, and I also tried to submit the form and got an error.

    Apart from that, please make sure the field type in Mailchimp is a normal text field so that it can receive any value. And make sure the field name is exactly the same as the merge tag (case sensitive).

    Kind regards,

    Thread Starter DataLife

    (@antibalashifi)

    Thanks. I see there was a duplicate field that had no value, and that’s what you saw. Try now.

    The current CF7 “code”:

    <label> Your Name (required)
        [text* your-name] </label>
    
    <label> Your Email (required)
        [email* your-email] </label>
    
    [mc4wp_checkbox]
    
    [submit "Subscribe"]

    It’s ok if I manually generate that field instead of putting it above, right? Flamingo is still seeing it, so mc4wp should be able to as well.

    Plugin Contributor Lap

    (@lapzor)

    We now can’t see the field at all in the code, or are we overlooking it?

    Can you test it by making a text field or hidden field and manually setting the value, so that you can find out if that part at least works?

    Kind regards,

    Thread Starter DataLife

    (@antibalashifi)

    Thanks, yes, I was successfully able to make a custom field that sent to Mailchimp, in that same form. I actually made sure to test that before starting this thread as I respect your time ??

    The field name is “unique-link” (I changed it from mc4wp-unique-link because that wasn’t working either). You should be able to search for it in Inspect/View Source, but here is a screenshot: https://picallow.com/form-3/?usp_success=2&post_id=310156&form_id=27.

    Plugin Contributor Lap

    (@lapzor)

    If it works when you manually created the field and assigned it a value, you have confirmed that on the side of our plugin things work properly, and the issue mus be with how you populate the field value in your own custom code.

    Thread Starter DataLife

    (@antibalashifi)

    Thanks. Okay I spent a bunch more time on this, and now have the field value properly populating inside the form — you should be able to see it. So what do I need to do to have mc4wp send it to Mailchimp? I’m now trying both of these to see if anything sticks in Mailchimp:

    [dynamichidden unique-link "custom_unique_link"]
    
    [dynamichidden mc4wp-unique-link "custom_unique_link"]

    As always, CF7 is submitting the fields properly. So it’s just a matter of getting mc4wp to send the custom field to Mailchimp.

    What would be amazing is if the mc4wp log would let us see what it’s receiving/sending to Mailchimp, but maybe it’s a niche request ??

    • This reply was modified 7 months ago by DataLife.
    • This reply was modified 7 months ago by DataLife.
Viewing 15 replies - 1 through 15 (of 24 total)
  • The topic ‘CF7 Custom Fields not going to Mailchimp’ is closed to new replies.