I have a webform which is doing fine sending most types of data to Mailchimp. However, I have postal addresses (constructed as individual fields in Webform) which I want to send to Mailchimp. What merge tag do I use?

The overall merge tag in Mailchimp is ADDRESS. I took a look at the Mailchimp API documentation and found the fields seem to be listed there under "contact":

  • address1
  • address2
  • city
  • state
  • zip
  • country

I've tried various combinations such as:

ADDRESS|post_code
ADDRESS:ZIP|post_code
ADDRESS:zip|post_code
ADDRESS{zip}|post_code

...etc, etc - but can't get any data into the address field.

Any suggestions please?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

adam_b’s picture

After a lot of back-and-forth with MailChimp, they pointed me to this page which says you need to use double spaces to separate address elements. However, I've tried that and it still doesn't work.

Their only other suggestion is to use individual fields - which gets the info to MailChimp OK but has nasty effects further down the line.

Has anybody ever managed to get data into the MailChimp Address field? Am I doing something else wrong? Or is there a bug somewhere?

dalemoore’s picture

Were you able to get the Address field into MailChimp? I've been trying to figure this out for a week with no luck.

adam_b’s picture

No - I had to use individual fields in the end :(

junaidpv’s picture

Version: 7.x-1.x-dev » 8.x-5.x-dev

We are also having issue with sending Address field values to MaillChimp. It is the value we use in "Merge vars" settings of "MailChimp" handler for the webform:

FNAME: '[webform_submission:values:first_name]'
LNAME: '[webform_submission:values:last_name]'
PHONE: '[webform_submission:values:phone]'
ADDRESS:
  addr1: '[webform_submission:values:your_address:address]'
  addr2: '[webform_submission:values:your_address:address_2]'
  city: '[webform_submission:values:your_address:city]'
  state: '[webform_submission:values:your_address:state_province]'
  zip: '[webform_submission:values:your_address:postal_code]'
  country: 'US'

I debugged and verified it building correct array structure from above yaml format. MailChimp contacts get values for LNAME, FNAME, PHONE. But it does not get values for address field.

junaidpv’s picture

Category: Support request » Bug report
Status: Active » Needs review
FileSize
726 bytes

Found my above configuration did not work because the webform handler plugin using array_filter on mergevars. Which of course did not work for multi dimensional array. Removing array_filter fixed it. It now send the address field data to MailChimp service.

adam_b’s picture

Glad to see someone sorted this, even if it's six years later ;)

lomale@bluewin.ch’s picture

Hi I'm coming in to this
because I have the same problem.
Mailchimp does not accept - the webform values out of

address
address_2
city
state_province
postal_code
country

to Mailchimp
address1
address2
city
state
zip
country

now Junaidpv can you tell me where you applied the patch. I'm not familiar with patches.
I would appreciate a lot for your help.

lomale@bluewin.ch’s picture

Version: 8.x-5.x-dev » 8.x-5.9
Component: Documentation » Code
Status: Needs review » Needs work
junaidpv’s picture

@lomale

Please put the patch file within "webform_mailchimp" module directory.

Guessing you already have GIT installed. Run this command to check if the patch will apply:

git apply --check -v 2385763-remove-filtering.patch

If it does not give any error, then run:

git apply -v 2385763-remove-filtering.patch

lomale@bluewin.ch’s picture

HI junaidpy

Thanks for replying.
I'm just a user and I struggle with all these technical issues. git - drush - composer.

I just made it installing composer and using it.
Is there an way to install it using composer??

or can you tell me in which file I could paste these lines manually.

I know this sounds weird. I'm just a user.

Thanks for your further help.

lomale

lomale@bluewin.ch’s picture

OK I just checked

The code should come into somewhere in the file

WebformMailChimpHandler.php

which line and how??

OR could you put it into it manually and send it as file.
So I would copy back the file.
I would appreciate a lot.

Thanks.

lomale

junaidpv’s picture

@lomale,

I re-read your original statement. I see you having issues with fields other than address fields, so the patch is unlikely to fix the problem for you.

Anyway, please try sending your file to me. I will try to help. Please use contact form available in my profile https://www.drupal.org/u/junaidpv

lomale@bluewin.ch’s picture

HI All

Even copying the patch on #5 the into WebformMailChimpHandler.php round Line 320 manually

= replacing the line 320 with
mailchimp_subscribe($configuration['list'], $email, $mergevars, $configuration['interest_groups'], $double_optin);

worked for me.

litte difference. I had to take away the Quotation marks
compared to #4

FNAME: [webform_submission:values:first_name]
LNAME: [webform_submission:values:last_name]
PHONE: [webform_submission:values:phone]
ADDRESS:
addr1: [webform_submission:values:your_address:address]

Thanks junaidpv

Todd Zebert’s picture

I had this same issue, so thanks all this was helpful. Turns out my code was never going to work as I was trying to populate *just* Country as MC enforces mandatory address subfields, so in case anyone else gets bit by this:

address:
a JSON object with the required keys addr1, city, state, and zip, and the optional keys addr2 and country. Values for these fields must be strings.

https://mailchimp.com/developer/marketing/docs/merge-fields/

amadhav1’s picture

I'm having the same issue, this is what I have:

delivery_address(section)
address_1
address_2
city
province
postal_code
country_code

to Mailchimp
addr_1
addr_2
city
state
zip
country

This is what I have in my webforms handler:

ADDRESS:
addr1: [webform_submission:values:delivery_address:address_1]
addr2: [webform_submission:values:delivery_address:address_2]
city: [webform_submission:values:delivery_address:city]
state: [webform_submission:values:delivery_address:province]
zip: [webform_submission:values:delivery_address:postal_code]
country: [webform_submission:values:delivery_address:country_code]

Even after I added patch on #5, when I try and submit I get errors. The Address breaks it, it looks like it is treating every sub-field as a separate address field.

Thanks,

Aaron

mrshowerman’s picture

FileSize
716 bytes
1018 bytes

Re-roll of #5.

lomale@bluewin.ch’s picture

Issue tags: +Needs documentation

Hi im back
As mentioned in #13

litte difference. I had to take away the Quotation marks
compared to #4

FNAME: [webform_submission:values:first_name]
LNAME: [webform_submission:values:last_name]
PHONE: [webform_submission:values:phone]
ADDRESS:
addr1: [webform_submission:values:your_address:address]

But now running Drupal 9.59 and Webform Mailchimp 8.x-5.10

it only works with Quotes

FNAME: '[webform_submission:values:vorname]'
LNAME: '[webform_submission:values:name]'
ANREDE: '[webform_submission:values:gender]'
TITEL: '[webform_submission:values:titel_beruf]'
PHONE: '[webform_submission:values:phone]'
ADDRESS:
addr1: '[webform_submission:values:address:address]'
city: '[webform_submission:values:address:city]'
state: '[webform_submission:values:address:state_province]'
zip: '[webform_submission:values:address:postal_code]'
country: '[webform_submission:values:address:country]'

so it works again.

solarDog’s picture

Drupal 10.2.2
Webform Mailchimp 8x5.10

I am having similar issues with mapping my webform (6.2) address fields to the mailchimp Address.
I have tried patch from #16 with no success. The contact does not come into mailchimp using the patch, so I have reverted.
Does not seem to make a difference if I use quotes or not.

FNAME: '[webform_submission:values:first_name]'
LNAME: '[webform_submission:values:last_name]'
COLLUNIV: '[webform_submission:values:college_university]'
DEGREE: '[webform_submission:values:degree_program]'
PHONE: '[webform_submission:values:phone_number]'
ADDRESS:
addr1: '[webform_submission:values:your_address:address]'
city: '[webform_submission:values:your_address:city]'
state: '[webform_submission:values:your_address:state_province]'
zip: '[webform_submission:values:your_address:postal_code]'

Everything but the address comes into with the Mailchimp contact. Does anyone have any insight into why this would be happening?

EDIT/UPDATE: I was able to get this working by indenting the addr1, city, state,zip like so.

ADDRESS:
  addr1: [webform_submission:values:your_address:address]
  city: [webform_submission:values:your_address:city]
  state: [webform_submission:values:your_address:state_province]
  zip: [webform_submission:values:your_address:postal_code]

Hope this helps someone else.