Happy Easter together!
I’ve created a custom action under plugins/uniform-actions.php
for the uniform plugin. But whenever I test my Form it fails with an error saying Uniform\Actions\SaveFormData does not exist.
What am I doing wrong?
Custom Action
<?php
namespace Uniform\Actions;
class SaveFormData extends Action
{
/**
* Dump the form data.
*/
public function perform()
{
$form = $this->form->data();
// Create a page title
$data = array_merge($form, [
'title' => $form['name'] . ' ' . $form['firstname'],
]);
$uid = 'contact/' . md5($data['email']);
// Check if the page already exists
// before trying to create it
if (! page($uid)) {
page()->create(
$uid,
'contact', // template name
$data
);
// Store the page uid on a session
// to be used on the success page
$session->set('formSubmission', $uid);
}
}
}
Controller
<?php
use Uniform\Form;
return function ($kirby)
{
$form = new Form([
'name' => [],
'firstname' => [],
'email' => [],
]);
if ($kirby->request()->is('POST')) {
$form->action(Uniform\Actions\SaveFormData::class)
->logAction([
'file' => kirby()->roots()->site().'/messages.log'
]);
}
return compact('form');
};