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
Ok good you got it working, what was the problem if you don't mind.
I just hoped maybe i got lucky lol
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!