I am attempting to use a Uniform form to send an email & submit an email address to Mailchimp.
The form sends out the 2x emails perfectly (1 to the client & 1 to the customer). However nothing is being submitted to Mailchimp. I am assuming the issue lies in the ‘data’ or ‘headers’ params. Any help would be super appreciated.
<?php
use Uniform\Form;
return function ($kirby)
{
$form = new Form([
'name' => [
'rules' => ['required'],
'message' => 'Please enter your name',
],
'email' => [
'rules' => ['required', 'email'],
'message' => 'Please enter a valid email address',
],
'title' => [],
'organisation' => [],
'tel' => [],
'message' => [],
]);
if ($kirby->request()->is('POST')) {
$form->emailAction([
'to' => 'testemail@test.com',
'from' => 'testemail@test.com',
'subject' => 'Newly submitted website form',
])
->webhookAction([
'url' => 'https://us5.api.mailchimp.com/3.0/lists/XXXXXXXXXX/members/',
'json' => true,
'params' => [
'method' => 'POST',
'data' => ['status' => 'pending'],
'headers' => ['Authorization: apikey XXXXXXXXXXXXXXXX-XXX'],
],
])
->emailAction([
// Send the success email to the email address of the submitter.
'to' => $form->data('email'),
'from' => 'hello@test.com',
'replyTo' => 'hello@test.com',
'subject' => 'Thank you for your message.',
'template' => 'success',
]);
}
return compact('form');
};