FormiIt with Mailchimp subscribe to list not working

I’ve installed FormIt and also the Mailchimp for FormIt Extra.
I did setup everything like mentioned in the README:

How to get set up

  1. Add Mailchimp API Key in systemsettings: mailchimpsubscribe.mailchimp_api_key
  2. Create a new single select TV variable and set the input option values to:
    @EVAL return $modx->runSnippet(‘MailChimpGetLists’);
  3. Add Mailchimp List ID TV in systemsettings: mailchimpsubscribe.list_tv
  4. Add MailChimpSubscribe to your FormIt hooks
  5. Add in your chunk the placeholder fi.error.mailchimp, which holds all Mailchimp error messages.
  6. Add a field called newsgroup, if the value of this field is set to yes, the user will be subscribed to the mailchimp list.

Adding to point 3: I’ve created a Listbox (Single-Select) TV, named it mailChimpList assigned it as requested in the system settings and also assigned it to the resource my subscription form lives on and assigned the wanted list through the resource settings.

Here’s my form and FormIt call:

    &successMessage=`Email sent!`
    &mailchimpListId=`2f********`          // hidden


<form action="[[~[[*id]]]]" method="post" id="newsletter">        
   <input type="hidden" name="nospam" value="" />
   <input type="hidden" name="newsgroup" value="yes" />
   <label for="email">[[!]]</label>
   <input type="text" name="email" id="email" value="[[!]]" placeholder="Email" />
   <input type="submit" value="Subscribe">

I think it might have something to do with the &mailchimpSubscribeField as I admit I don’t understand what that does or what it’s for. The README states:

  • mailchimpSubscribeField: Field name to use for subscribing users to mailchimp.
  • mailchimpSubscribeFieldValue: Field value to use for subscribing users to mailchimp.

Seems clear but somehow I don’t get what to do with it.

Overall I can submit the form and even get the success message but it’s not sending me the opt-in email and also there is no email entry in the mailchimp list when I check it there. Any suggestions?

I think that the mailchimpSubscribeField should be called newsgroup not newsletter.


Then it will match up with the value entered in your input field

<input type="hidden" name="newsgroup" value="yes" />

If I change it to newsgroup I get this error:

Invalid Resource: The resource submitted could not be validated. For field-specific details, see the ‘errors’ array.

How can I check the errors array? That’s not the general MODX log, is it?

I called it newsletter as it’s named that way in the docs:

Basic usage without tags


Try adding this to the page where your call FormIt:

[[!+fi.error_message:notempty=`<p class="error">[[!+fi.error_message]]</p>`]]

Then I get the same error twice :smile:

I’m not familiar witth the extra but I use a custom hook for quite a while now to add members to a list in Mailchimp. It’s quite easy.

Take a look at:

1 Like

Thanks @ilja-web, that works indeed easy and straight forward. I still would like know what the issue is with the plugin if anybody has an idea?

1 Like

Was trying to get the same extra working and also ran into the Invalid Resource: The resource submitted could not be validated. For field-specific details, see the ‘errors’ array. error.

The plugin does a very poor job of error handling and passing API errors back into view, but with some debugging (read: editing the plugins’ code to dump errors to screen) I finally managed to track down a more useful error:

array(6) {
  ["type"]=> string(77) "" 
  ["title"]=> string(16) "Invalid Resource" 
  ["status"]=> int(400) 
  ["detail"]=> string(98) "The resource submitted could not be validated. For field-specific details, see the 'errors' array." 
  ["instance"]=> string(36) "<..>" 
  ["errors"]=> array(1) { 
    [0]=> array(2) { 
      ["field"]=> string(12) "merge_fields" 
      ["message"]=> string(36) "This value should be of type object." 

That indicates a problem with the merge_fields being sent, which upon further inspection was being passed as empty:

array(3) {
  ["email_address"]=> string(16) "" 
  ["merge_fields"]=> array(0) { } 
  ["status"]=> string(7) "pending" 

This appears to have been due to the &mailchimpFields property on the FormIt call which only contained the email in my case, just like the code snippet in the opening post here: &mailchimpFields=`email=EMAIL`

After updating that to also include another merge field (&mailchimpFields=`email=EMAIL,name=FNAME`), the subscribe finally started to work.

Another undocumented thing to note is that the API Key needs to be in the format <key>-<dc> where <dc> is the datacenter, like us2. The API Key I was originally provided was incorrect and missed the DC causing it to not work as well. Again, the plugin does a poor job of communicating such errors, so that takes some digging :confused:

1 Like

Ladies and Gentlemen, I present to you @markh (the h stands for Holmes :face_with_monocle:) Great work! Thanks alot!

In my case, I simply delivered an empty hidden name field as I’m quite sure you are not allowed to ask for a name with the email for a newsletter due to GDPR.

I didn’t have the issue with the API Key, as I got mine directly from the mailchimp menu where it has the needed format. Still important to know though, as some might get it from a client or otherwise.

Another thing to note is, that you might not need the API Key at all, if you’re entering the mailchimp List ID directly via &mailchimpListId as stated on the extras website:

  • Option 1: Create a new single select TV variable and set the input option values to:
    @EVAL return >$modx-&gt;runSnippet('MailChimpGetLists');
    Add MailChimp List ID TV in systemsettings: mailchimpsubscribe.list_tv
  • Option 2: Set the FormIt scriptProperty &mailchimpListId to the correct MailChimp List ID

To make this thread complete, here’s my working code:

   &hooks=`spam, MailChimpSubscribe`
   &successMessage=`Awesome! Please check your inbox to verify your subscription.`

<form id="newsletter" action="[[~[[*id]]]]#newsletter" method="post">   
   [[!+fi.successMessage:notempty=`<span class="success">[[!+fi.successMessage]]</span>`]]

   <input type="hidden" name="nospam" value="" />
   <input type="hidden" name="newsgroup" value="yes" />
   <input type="hidden" name="name" value="" />
   <input type="email" name="email" id="email" placeholder="Email address" value="[[!]]" required />
   <button type="submit">Subscribe</button>

If there’s an issue with the mailchimpLists TV not showing the Lists in the Resource although everything is setup right, manually clearing the core/cache did it for me.

1 Like

Heh, I may have to change my last name! :wink:

You do still need the API Key to subscribe the user even if you don’t use the TV to select the list/audience :wink:

1 Like

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.