I run into an issue where I can’t fetch my forms data when it’s used under the home template. It appears to be only reloading the site but not posting the forms data.
I have tested this with a plain starterkit and the cookbook receipt here. The same template works fine if I rename it to a different template name e.g contact.
It seems that / is not treated equally as home where <form method="post" action="<?= $page->url() ?>">. Does this require a special route?
Controller and template are identical from the cookbook receipt. Tested on the latest version 3.5.3.1.
When I add the dump($data) it’s empty when I have the form on the home template. When I rename the template and controller to any other name which is not the home page e.g. contact, dump($data) shows all the data from my submitted form. It’s a little bizarre…
if($kirby->request()->is('POST') && get('submit')) {
// check the honeypot
if(empty(get('website')) === false) {
go($page->url());
exit;
}
$data = [
'email' => get('email'),
];
$rules = [
'email' => ['required', 'email'],
];
$messages = [
'email' => 'Please enter a valid email address',
];
// some of the data is invalid
if($invalid = invalid($data, $rules, $messages)) {
$alert = $invalid;
// the data is fine, let's send the email
} else {
try {
dump($data);
} catch (Exception $error) {
if(option('debug')):
$alert['error'] = 'The form could not be sent: <strong>' . $error->getMessage() . '</strong>';
else:
$alert['error'] = 'The form could not be sent!';
endif;
}
// no exception occurred, let's send a success message
if (empty($alert) === true) {
$success = 'Your message has been sent, thank you. We will get back to you soon!';
$data = [];
}
}
}
return [
'alert' => $alert,
'data' => $data ?? false,
'success' => $success ?? false
];
And your home page is not redirected to another page with another template? And the contend file in the home folder is called home.txt? No funny redirect routes?