Kirby

What should be controller name for form, that can be on any page?

I want to have form in modal window, so it can be opened from any page. As I understand, name of controller file should have the same name, as name of page template, from which form is sent, but then what should it be if form can be on any page (different pages will have different templates)?

If you don’t need any other controllers, you can use the site/controller/site.php fallback controller for every page.

Thanks, but probably will need, also will have at least one other form.

You can put the form handling logic into your form snippet (instead of into a controller)

Or you can use a shared controller by requiring it in every other controller, and returning the stuff from it along with the stuff in that specific controller. I do this on sites when i need something like a newsletter signup on every page.

<?php

return function($kirby, $site, $pages, $page) {

  // Import Global Controller
  require_once kirby()->root('controllers') . '/shared/global.php';

  $currenttag = $kirby->request()->params()->tag();

  return [
    'sharedthing' => $sharedthing,
    'currenttag' => $currenttag
  ];
};

While that‘s possible I don’t really see an advantage. Whenever you add a new template, you have to add the shared controller which just results in a lot of duplicated code.