Hi all - I’m using uniform in my Kirby 4 site for a customer sign up form. I want the form to be cc’d to the customer’s 'email (‘accountsEmail’ variable), and each use different email templates.
To do this I’ve set up two separate email actions and am retreiving the ‘accountsEmail’ from the array at the top of the controller, yet the form fails because the accountsEmail variable isn’t being included in the POST data.Where am I going wrong?
Thanks in advance!
Controller:
<?php
use Uniform\Form;
return function ($kirby)
{
$form = new Form([
'tradingName' => [],
'companyType' => [],
'limitedCompanyName' => [],
'companyRegistrationNumber' => [],
'tradingStartDate' => [],
'companyPhone' => [],
'deliveryAddressLine1' => [],
'deliveryAddressLine2' => [],
'deliveryTownCity' => [],
'deliveryPostCode' => [],
'deliveryCounty' => [],
'accountsEmail' => [],
]);
if ($kirby->request()->is('POST')) {
$form->setData($kirby->request()->data());
$form->turnstileGuard();
if ($form->validate()) {
$applicationId = 'REF' . date('ymd') . rand(100, 999);
$form->set('applicationId', $applicationId);
$customerEmail = $form->get('accountsEmail');
// Admin email
$form->emailAction([
'to' => 'info@domain.com',
'from' => 'website@domain.com',
'subject' => 'New trade account application received',
'template' => 'signup',
'data' => [
'form' => $form,
'applicationId' => $applicationId,
'recipient' => 'admin',
],
]);
// customer email
$form->emailAction([
'to' => $customerEmail,
'from' => 'website@domain.com',
'subject' => 'Your application confirmation',
'template' => 'signup',
'data' => [
'form' => $form,
'applicationId' => $applicationId,
'recipient' => 'customer',
],
]);
// 8. Log submission for record keeping
$form->logAction([
'file' => kirby()->roots()->site() . '/messages.log',
]);
// 9. Mark form as successfully processed
$form->success(true);
}
}
return compact('form');
};