hi!
i’m pretty new to kirby and especially to php trying to figure out step by step how to change content via forms from the frontend. i got the “creating pages from frontend” tutorial and was wondering how to do similar things, e.g. simply editing field data from a specific page, using the uniform plugin (advantage: clean code and more structure for having more than one form?) and custom actions.
my code:
template:
<form action="<?php echo $page->url() ?>" method="POST">
<input name="eingabe1" type="text" value="<?php echo $form->old('ptext') ?>" placeholder="text">
<?php echo csrf_field() ?>
<?php echo honeypot_field() ?>
<input type="submit" value="Submit">
</form>
controller:
<?php
use Uniform\Form;
return function ($site, $pages, $page)
{
$form = new Form([
'eingabe1' => []
]);
if (r::is('POST')) {
$form->changeText(['neuertext' => $form]);
};
return compact('form');
};
“changeText action”:
<?php
namespace Uniform\Actions;
use Error;
use Uniform\Form;
class changeText extends Action {
public function perform() {
$neuertext = $this->form->data();
try {
page('testin')->update(['text' => $neuertext]);
} catch (\Exception $e) {
$this->fail($e->getMessage());
}
}
}
i think the input is not submitted to $form but to be honest, i don’t really get what is/should happen there. maybe someone could explain how the form input goes into into the $form variable, or maybe i just get the whole thing wrong.
thanks in advance!
dennis