We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22197
    • 40 Posts
    Hi

    I can't get Sterc's extra to add subscribers to MailChimp lists using FormIt and the MailChimp API to work.

    This is the input field I use for the email address:
    <input type="text" placeholder="E-mailadres" name="email" id="check" value="[[+fi.email]]" aria-describedby="HelpMyemail" required pattern="email" >

    I added a (hidden) field called newsgroup and as described in the documentation, gave it the value "yes".
    <input type="hidden" id="newsgroup" name="newsgroup" value="yes" />

    The API key in defined in the systems settings.

    I call formit with the following scriptproperties:

    [[!FormIt?
    &hooks=`MailChimpSubscribe,spam,redirect`
    &submitVar=`go`
    &validationErrorMessage=`something wrong`
    &mailchimpListId=`a1c189980c`
    &redirectTo=`189`
    &validate=`
    email:email:required,
    newsgroup:required`
    ]]


    When I leave the email address empty, I get an error message from Mailchimp, which indicates - I believe - that I've got the API working. But, when I enter a proper email address, nothing happens. Formit isn't redirecting, Mailchimp isn't giving an error message.

    Any idea what might be wrong?

    Regards


    Ludo
      • 46886
      • 1,154 Posts
      name="email" id="check"


      This looks highly suspicious to me. the names and ids and so on are always the same for a value. every other value in that string is "email", where did that "check" come from?

      I could be totally off base but it looks weird
        • 22197
        • 40 Posts
        Quote from: nuan88 at Jun 03, 2018, 06:52 PM
        name="email" id="check"


        This looks highly suspicious to me. the names and ids and so on are always the same for a value. every other value in that string is "email", where did that "check" come from?

        I could be totally off base but it looks weird

        It might be weird, but I think it's not the problem.

        I managed to make it work, but it looks like Mailchimp always wants the subscriber to confirm the subscription via email even if you haven't checked the "Enable double opt-in" checkbox in the Form Settings.

        Ludo
          • 46886
          • 1,154 Posts
          Ok good you got it working, what was the problem if you don't mind.

          I just hoped maybe i got lucky lol
            • 22197
            • 40 Posts
            Quote from: nuan88 at Jun 03, 2018, 09:21 PM
            Ok good you got it working, what was the problem if you don't mind.

            I just hoped maybe i got lucky lol

            I removed all the other fields in the form. And then I tried it again and discovered the reditect was working. Then I checked my email to find an email from Mailchimp with the request to confirm the subscription. I did check the Form Settings to be sure: no, I had not marked the 'Enable double opt-in" feature. Can anybody confirm that Mailchimp enforces double opt-in if you use the API?

            Ludo
              • 38783
              • 571 Posts
              Mailchimp for MODX seems to set the status as 'pending' via the API. This is what makes Mailchimp require the double opt in.

              This is set in: mailchimpsubscribe/model/mailchimpsubscribe/mailchimpsubscribe.class.php

              I changed the first line in this block of code from 'pending' to 'subscribed' and now my subscriptions do not require a double opt in.

                      $subscribeStatus = 'subscribed';
                      if ($this->mcSubscribeMode === 'update') {
                          $result = $mc->PATCH(
                              '/lists/'. $listId . '/members/' . md5($userEmail),
                              [
                                   'email_address' => $userEmail,
                                   'merge_fields'  => [
                                       $this->mcFieldName    => $userName,
                                       $this->mcFieldLName    => $userLName,                       
                                       $this->mcFieldCompany => $company
                                   ],
                                   'status' => $subscribeStatus
                              ]
                          );
                      } else {
                          $result = $mc->post(
                              '/lists/'. $listId . '/members',
                              [
                                  'email_address' => $userEmail,
                                  'merge_fields'  => [
                                      $this->mcFieldName    => $userName,
                                       $this->mcFieldLName    => $userLName,                       
                                      $this->mcFieldCompany => $company
                                  ],
                                  'status' => $subscribeStatus
                              ]
                          );
                      }
              


              I have not encountered any problems as a result of doing this, but I can't guarantee that it is not going to cause some unforeseen issue!
                If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

                email: [email protected] | website: https://andytough.com
                • 22197
                • 40 Posts
                Quote from: andytough at Jun 05, 2018, 07:39 AM
                Mailchimp for MODX seems to set the status as 'pending' via the API. This is what makes Mailchimp require the double opt in.

                This is set in: mailchimpsubscribe/model/mailchimpsubscribe/mailchimpsubscribe.class.php

                I changed the first line in this block of code from 'pending' to 'subscribed' and now my subscriptions do not require a double opt in.

                        $subscribeStatus = 'subscribed';
                        if ($this->mcSubscribeMode === 'update') {
                            $result = $mc->PATCH(
                                '/lists/'. $listId . '/members/' . md5($userEmail),
                                [
                                     'email_address' => $userEmail,
                                     'merge_fields'  => [
                                         $this->mcFieldName    => $userName,
                                         $this->mcFieldLName    => $userLName,                       
                                         $this->mcFieldCompany => $company
                                     ],
                                     'status' => $subscribeStatus
                                ]
                            );
                        } else {
                            $result = $mc->post(
                                '/lists/'. $listId . '/members',
                                [
                                    'email_address' => $userEmail,
                                    'merge_fields'  => [
                                        $this->mcFieldName    => $userName,
                                         $this->mcFieldLName    => $userLName,                       
                                        $this->mcFieldCompany => $company
                                    ],
                                    'status' => $subscribeStatus
                                ]
                            );
                        }
                


                I have not encountered any problems as a result of doing this, but I can't guarantee that it is not going to cause some unforeseen issue!

                Great tip! Thank you very much.

                Ludo