Calling variables in form email action

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');
};

I don’t understand where the email is supposed to come from. Please post the form html

Thanks for the reply @texnixe

So that is in the array here:

and is from the fteld in the application form here:

<input type="email" class="form-control" id="accounts-email" name="accountsEmail" required>

Then taking that and defining it for the email action as follows:

$customerEmail = $form->get('accountsEmail')

Where did you get this `$form→get()` method from?

Apologies for late reply @texnixe - been in hospital! Managed to sort this by getting the relevant email address directly from the initial array in the controller.