Hello,
I am using Uniform for an AJAX form.
When the form is received via email, the “Email” submitted in the input by the user is not included.
The route looks like:
'routes' => [
[
'pattern' => '(:all)',
'method' => 'POST',
'action' => function () {
$form = new \Uniform\Form([
'name' => [],
'email' => [
'rules' => ['required', 'email'],
'message' => 'Please enter a valid email address',
],
'message' => [
'rules' => ['required'],
'message' => 'Please enter a message',
],
]);
// Perform validation and execute guards.
$form->withoutFlashing()
->withoutRedirect()
->guard();
if (!$form->success()) {
// Return validation errors.
return Response::json($form->errors(), 400);
}
// If validation and guards passed, execute the action.
$form->emailAction([
'to' => 'emailaddress@gmail.com',
'from' => 'form@website.com',
]);
if (!$form->success()) {
// This should not happen and is our fault.
return Response::json($form->errors(), 500);
}
// Return code 200 on success.
return Response::json([], 200);
}
]
]
The form is:
<form class="form__contact" action="<?= $page->url() ?>" method="POST">
<input name="name" placeholder="Name" type="text">
<input name="email" placeholder="Email" type="email">
<div class="textarea__wrapper">
<textarea placeholder="Message" name="message"></textarea>
</div>
<?php echo csrf_field() ?>
<?php echo honeypot_field() ?>
<p id="message"></p>
<input type="submit" value="Submit">
</form>
My understanding is that Uniform’s default template will grab and display each $field and $value however when I receive the email it is just:
Name: Inputted Name
Message: Inputted Message
Any ideas @mzur ? I am sure I am just missing something very simple