When you try to submit a field other than the email address, MailChimp will not accept the value. I believe I have narrowed it down to this line of code, but I am starting to go cross-eyed looking at it. I would appreciate any help. I beleive the issue is with the format of the array.

Line 98 of webform_mailchimp.module
$mergefields_replacements[$mergefields_key_array[$field['form_key']]] = $submission->data[$key]['value'][0];

I have also manually created the array for $mergefields_replacements, and MailChimp will accept those values. The code that I used to test it, is below.
$mergefields_replacements = array('FNAME' => 'John');

Thanks,

TJ

Comments

tjferre’s picture

I have narrowed down the issue a little further.
I believe that $mergefields_key_array is not being set properly. The only value it contains is the email field. The $mergefields_key_array should only contain mailchimp fields excluding the email. The email is set already and should not be included in the $mergefields_key_array. The email is the first field of $field['extra']['mergefields'], subsequent mailchimp fields are not being not being included in $mergefields_key_array. I would appreciate any help in resolving this issue.

Line 61 of webform_mailchimp.module

// Retrieve mergefields and create a merge array with key webform key and value Mailchimp merge tag
        if (!empty($field['extra']['mergefields'])) {
          $mergefields_key_array = array();
          $keyvaluepairs = explode("\n", $field['extra']['mergefields']);

          foreach ($keyvaluepairs AS $keyvalue) {
            $keyvalue = trim($keyvalue);
            $keyvalue = explode('|', $keyvalue);
            if (is_array($keyvalue) && !empty($keyvalue[0]) && !empty($keyvalue[1])) {
              $mergefields_key_array[$keyvalue[1]] = $keyvalue[0];
            }
          }
        }

Drupal 7.14

tjferre’s picture

I have narrowed it down a little further. The issue I found is that the mergefields are not being seperated correctly. I am still trying to narrow down how the field should be exploded but \n is not working.

$keyvaluepairs = explode("\n", $field['extra']['mergefields']);

TJ

jpburn’s picture

        // Retrieve mergefields and create a merge array with key webform key and value Mailchimp merge tag
        if (!empty($field['extra']['mergefields'])) {
          $mergefields_key_array = array();
          $keyvaluepairs = explode("\n", $field['extra']['mergefields']);

          foreach ($keyvaluepairs AS $keyvalue) {
            $keyvalue = trim($keyvalue);
            $keyvalue = explode('|', $keyvalue);
            if (is_array($keyvalue) && !empty($keyvalue[0]) && !empty($keyvalue[1])) {
              $mergefields_key_array[$keyvalue[1]] = $keyvalue[0];
            }
          }
        }

        // Retrieve interestfields and create a merge array with key webform key and value Mailchimp group name
        if (!empty($field['extra']['interestfields'])) {

$groupfields_key_array = array(); //put this array outside of the for loop and it will work

      $keyvaluepairs = explode("\n", $field['extra']['interestfields']);

          foreach ($keyvaluepairs AS $keyvalue) {
            $keyvalue = trim($keyvalue);
            $keyvalue = explode('|', $keyvalue);
            if (is_array($keyvalue) && !empty($keyvalue[0]) && !empty($keyvalue[1])) {
              $groupfields_key_array[$keyvalue[1]] = $keyvalue[0];
            }
          }
        }

      }
    }

jpburn’s picture

Issue summary: View changes

Changed the wording

VanessaM’s picture

can you explain how this can be fixed? I am having the same problem and am not a programmer.

thanks!

lionsharz’s picture

Issue summary: View changes

I'm still having this issue with the latest dev plus patches for the 4.x branch of MailChimp and the 4.x branch of Webform.

I can add subsribers from the Webform without any merge fields, interest fields, double opt-in but as soon as I add *any* of those merge fields to the box or interest groups or double opt-in the subscription fails.

I've changed the code as above with the patched dev version (https://www.drupal.org/node/1052290 committed to latest dev to work with 4.x branch) but no joy. No error messages are showing.

Any pointers?

knalstaaf’s picture

Version: 7.x-1.0-rc2 » 7.x-4.x-dev
knalstaaf’s picture

Status: Active » Fixed

Clearing the cache worked for me.
Reopen if deemed necessary.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.