I’m using Uniform to send an email with dynamics fields added via JS. This is working as per the Uniform example (Dynamic Fields - Kirby Uniform) but I’m struggling to get my head around how to access these extra fields in the email template I send. It appears that they just get added to the bottom of the data array, but I need to position them in a specific place in the email so I can’t just loop through the data array, I need to target them specifically. Unlike the Uniform example, I have multiple fields and the user can add as many as they want via the form.
From the Uniform example:
<?php
use Uniform\Form;
return function ($kirby)
{
$rules = [
'email' => [
'rules' => ['required', 'email'],
'message' => 'Please enter a valid email address',
],
'name' => [],
];
$shopItems = array_filter($kirby->request()->body()->toArray(), function ($key) {
return strpos($key, 'shopitem-') === 0;
}, ARRAY_FILTER_USE_KEY);
foreach ($shopItems as $name => $value) {
$rules[$name] = [
'rules' => ['required'],
'message' => 'The shop item must be present.',
];
}
$form = new Form($rules);
if ($kirby->request()->is('POST')) {
$form->emailAction([
'to' => 'me@example.com',
'from' => 'info@example.com',
])->done();
}
return compact('form', 'shopItems');
};
How would I grab the shopItems
array in the email template?