I’ve been really struggling with setting up a contact form on my site using the Forms plugin.
Almost all pages of my site are modular, with the header/branding and nav buttons and the footer being defined in twig templates in the templates/partials directory.
In in footer.html.twig I have some basic contact info, a map and the space for a simple contact form.
What I ideally want to be able to do is to define the form fields and form layout/formatting in one place - not, for example, in the frontmatter of every page’s modular.md, because a change to the layout would have to be carefully copied into each modular.md.
I’ve tried following the guide for a modular contact form, and I got the contact form to display with the other modular pages of a particular page in the area defined by {% block content %},{% endblock %} in base.html.twig, but I couldn’t get the form to display in the footer block.
I would really just like to know if it’s possible to have the contact form render in the footer of every page. If it’s possible, I’ll carry on messing aro und, but at the moment I’m worried I’m hashing my site about and confusing everything trying to achieve something that isn’t really possible with Grav!
Have you read how to display forms with Twig ? You can define the form once in a page (even a non-routable/hidden page), and then show it anywhere you want (in your case, in the footer)
Oh gosh - I did read that page, but I think I misunderstood what it was saying and ended up going round in circles. I’ve almost got it working (!), but I’ve got an error message when I submit the form: TypeError Argument 1 passed to Grav\Plugin\EmailPlugin::buildMessage() must be of the type array, null given, called in /home/grav/www/html/user/plugins/email/email.php on line 74.
So I’ve now created a hidden page called: contact-form-definition-hidden/default.md
and in the frontmatter for that page I defined the form.
I then created the file: user/themes/my-theme/templates/partials/contact-form-field.html.twig
in which I define how each field is rendered. To ensure my field definition overrides the default field definition, I added the line: {% extends "partials/contact-form-field.html.twig" %}
to the file: user/plugins/form/templates/forms/field.html.twig
My Email plugin is configured correctly (as far as I can see), because I’ve successfully sent messages from the site when I had the contact form shown on one page only.
Have you got any idea where I m ight look to try and fix this error?