Hey!
My goal is to build a counter for the amount of form submissions to an external form endpoint. So I came up the idea to write down each submit in a file and somebody linked to Creating pages from frontend | Kirby CMS but with the hint to do this with a strucured field instead. So I tinkered down the origin example and my testing code below is working. But if I add a value to the form’s action attribut, then the form itself works but there happens no entry in kirby anymore.
How do I have to solve this situatiuon?
This is my controller:
<?php
return function ($kirby, $page) {
if ($kirby->request()->is('POST') && get('register')) {
$data = [
'name' => get('name'),
];
$kirby->impersonate('kirby');
function addToStructure($page, $field, $data = array()){
$fieldData = page($page)->$field()->yaml();
$fieldData[] = $data;
$fieldData = yaml::encode($fieldData);
try {
page($page)->update(array($field => $fieldData),'de');
} catch(Exception $e) {
return $e->getMessage();
}
}
addToStructure($page, 'namen',[
'name' => get('name'),
]);
}
};
and this my template:
<form action="#"
method="POST"
id="form">
<label for="name">Name </label>
<input type="text" id="name" name="name" value="<?= $data['name'] ?? null ?>" required/>
<input type="submit" name="register" value="Senden" />
<div id="form-message"></div>
</form>