How do I setup my controller, if I want to use one parent template, that loads snippets with different forms. Here is what I have:
site/templates/form.blade.php
@extends('layouts.default')
@section('content')
// could be a kirby snippet
// <?= snippet($page->uid()) ?>
@includeIf('forms.' . $page->uid())
@endsection
/site/controllers/form.php - as far as I understand, this is the parent controller and I need so extend it somehow, but how?
<?php
use Uniform\Form;
return function ($kirby, $pages, $page)
{
// should the following go into a file that I include with
// require sprintf('/%s.php', $page->uid())
$form = new Form([
]);
if ($kirby->request()->is('POST')) {
}
//ddd($form);
return compact('form');
};
/site/templates/forms/besucheranmeldung.blade.php
<form method="POST">
<input name="email" type="email" value="<?php echo $form->old('email') ?>">
<textarea name="message"><?php echo $form->old('message') ?></textarea>
<select name="recipient">
<?php $value = $form->old('recipient') ?>
<option value="sales"<?php e($value=='sales', ' selected')?>>Contact sales</option>
<option value="marketing"<?php e($value=='marketing', ' selected')?>>Contact marketing</option>
<option value="feedback"<?php e($value=='feedback', ' selected')?>>Give feedback</option>
</select>
<?php echo csrf_field() ?>
<?php echo honeypot_field() ?>
<input type="submit" value="Submit">
</form>
/content/5_kontakt/besucheranmeldung/form.de.txt
Title: Besucheranmeldung
----
Slug: besucheranmeldung
I have to create a lot of forms and don’t want to create too many templates and blueprints, or am I overlooking something?
The controller (controllers/form.php) is determined by the content/**/besucheranmeldung/form.txt, but is there a place to define that /controllers/besucheranmeldung.php should be loaded?
How to approach this the best?