Use controller for mailform snippet

I load a mailform on every page as a snippet. my problem now is how can I use a controller now for the snippet?
Or have I create one for every template?


You only have to add the controller code to the “action” page. See this thread for an explanation: Newsletter form on multiple pages

Alternatively, there’s a great cookbook article about Shared Controllers.

Hi Thomas,
The contactform is in the footer on every page.
If I send the form to a special page with the controller how can I show than the return on the sender page?
In K2 I couldn‘t use the controllerfile for a Ajax solution. There I did it normally with a plug-in and routing.
Now I have copied the mailcontrollercode in my snippet. But the function doesn‘t work. I think I have to send the $kirby, $pages … parameters also to the snippet. But this first I have to test it to proof if this is the problem.

If I use the code without as a function, of course I get no $error or $succes returned but I have also the problem that my email-template is not used? But this should work and I don’t understand why it isn’t use my template.


Hi Jan, i am working on something similar /the same/ as you do. You can check my code here:
I too have a problem of calling the controller from my js code.
Could we perhaps exchange our code to come to a solution?

You mean a notice that the mail has been sent? I think there are at least two options: show the success message on the special page instead of on the page from which it was sent. Or redirect back to the calling page, storing the information you want to return in the session, see