bug: when using an address merge field on a Mail Chimp subscription form, data doesn't upload from a drupal based, MailChimp module enabled subscription form to the MailChimp Newsletter service.

To reproduce:
Create a subscription form at MailChimp.com that includes an address field and make sure it has a merge variable name.
At drupal site, sync with Mailchimp to get the new form
Test your form by going to /mailchimp/subscribe

What I see is that the address field is a single textbox, not the mutli-textbox grouping at MailChimp.
What worse, is that when I type in an address into the address field and submit the form, the information is lost.

Comments

rickmanelius’s picture

This also happens for me. None of the information makes it back to Mailchimp.

See similar issue here - http://drupal.org/node/581494

It seems its by design that the address fields are not broken down to their individual components. And this essentially renders them ineffective.

I've tried tinkering with this, but it's a bit more complicated than my current knowledge level will allow me to fix!

The magic appears to happen here...

  foreach ((array)$q->listMergeVars($list->id) as $mergevar) {
    $form[$mergevar['tag']] = _mailchimp_insert_drupal_form_tag($mergevar);
  }

Unfortunately, my client insists on the form people on his site... and so I can't even embed a form from mailchimp either! So I'm kinda stuck on this...

It doesn't seem to be a simple modification, as both the collection and submission portions have to be synced up.

rickmanelius’s picture

Nevermind... it does seem you can do a copy/paste of the full form.
http://server.iad.liveperson.net/hc/s-31286565/cmd/kbresource/kb-8430247...

Not as convienent, but doable for now!

rickmanelius’s picture

BTW, I've been messing with this all morning. But yes, if you absolutely need anonymous user subscriptions with address field informatin, you can easily do so by going to the form creator, getting an embeddable version with the non-required fields listed as well... and then make sure you have all the proper JS files included when you call this form.

This is probably a better solution for my case... but on another site, I want to have authenticated users with address information, so the merge vars thing is still a sticking point.

Exploratus’s picture

soooo. does this mean you cannot import an address from Drupal to Mailchimp? Really? Seems like an obvious need.

levelos’s picture

Status: Active » Closed (fixed)

Address fields are complex multi-part within MailChimp and can't be merged with a single token value. As a stop gap, I've prevented them from being used as a merge field and added some messaging along those lines. We need to move this into a feature request for the 7.x branch for supporting more complex merge fields.

chrisdfeld’s picture

Component: Code » General

Sorry to drag up an old issue, but I wrote some code a while back to handle MailChimp's combined address fields and have been meaning to share. This code can be used inside a custom helper module you would create and it maps Drupal address fields to MailChimp format only (not the reverse). Replace 'myhelpermodule' with your own module name in the code below. You must create Drupal profile fields corresponding to the MailChimp combined address field components, as follows:

  • Street Address (textfield) (aka Address Line 1)
  • Address Line 2 (textfield)
  • City (textfield)
  • State/Province/Region (textfield)
  • Postal / Zip Code (textfield)
  • Country (selection)

The Country field selection options must match the standard list of countries MailChimp offers in their drop-down list. You can scrape that list from any MailChimp sign-up form that uses a combined address field, like this one: http://eepurl.com/sVqL. You just need the textual country names, not MailChimp's numerical values, and be sure not to pick up any stray trailing spaces.

Make note of your Drupal internal field names and insert them in the appropriate spot in the code below. After enabling this helper code there will be a new merge key named "My Helper Module: MailChimp Combined Address" that can be used for mapping. Please note that I used this code with version 6.x-2.0-rc4, so it's possible the change levelos references above has altered the procedure in the interim.

Apologies for the rough nature of this write-up, but I no longer use this module and didn't find time to create a proper patch. I figured it would be better to post as-is rather than let it continue to collect dust.


module_load_include('php', 'mailchimp', 'MCAPI.class');

/**
 * Implementation of hook_mailchimp_merge_keys
 * Add support for MailChimp combined address merge field
 */
function myhelpermodule_mailchimp_merge_keys() {
  $out = array();
  $out['myhelpermodule_mailchimp_address'] = t('My Helper Module: MailChimp Combined Address', array('!field' => 'myhelpermodule_mailchimp_address'));
  return $out;
}

/**
 * Implementation of hook_mailchimp_merge_values
 * Add support for MailChimp combined address merge field
 */
function myhelpermodule_mailchimp_merge_values($user) {
  $out = array();
  $out['myhelpermodule_mailchimp_address'] = '';
  // MailChimp combined address format:
  //   Address1__Address2__City__State__Postal__Country
  // (with spaces instead of underscores)
  $profile_field_names = array(
    // replace values below with respective Drupal profile field names
    'address1' => 'FIXME_drupal_profile_field_name_address1',
    'address2' => 'FIXME_drupal_profile_field_name_address2',
    'city' => 'FIXME_drupal_profile_field_name_city',
    'state' => 'FIXME_drupal_profile_field_name_state',
    'postal' => 'FIXME_drupal_profile_field_name_zip_code',
    'country' => 'FIXME_drupal_profile_field_name_country',
  );
  $user_array = (array)$user;
  // sanitize data
  $profile_fields_clean = array();
  foreach ($profile_field_names as $field_type => $field_name) {
    $profile_fields_clean[$field_name] = $user_array[$field_name];
    // strip any newlines
    $profile_fields_clean[$field_name] = str_replace("\r", '', $profile_fields_clean[$field_name]);
    $profile_fields_clean[$field_name] = str_replace("\n", '', $profile_fields_clean[$field_name]);
    // strip any double spaces (that's the MailChimp field separator)
    // note: it is impossible to choose the country option:
    //   "Jersey__(Channel Islands)"
    // due to MailChimp's choice of field separator
    $replacements = 1;
    while ($replacements) {
      $profile_fields_clean[$field_name] = str_replace('  ', ' ', $profile_fields_clean[$field_name], $replacements);
    }
  }
  // glue fields into MailChimp combined address format
  $out['myhelpermodule_mailchimp_address'] = implode('  ', $profile_fields_clean);

  return $out;
}