Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Archive

Contact form in footer, shown on every page

Started by Muut Archive 9 years ago · 3 replies · 1631 views
9 years ago

Hi there,

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!

Thanks for the input.

Chris

9 years ago

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?

Thank you so much for your help.

Chris

9 years ago

OK, went back to basics, recreated everything and it's all working now. Think I had some issues with YAML indenting in the frontmatter.

Sorry for wasting your time on this :-(

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1318 9 years ago
Archive · by Muut Archive, 9 years ago
2 915 9 years ago
Archive · by Muut Archive, 9 years ago
2 4024 9 years ago
Archive · by Muut Archive, 9 years ago
1 2900 9 years ago
Archive · by Muut Archive, 9 years ago
3 1082 9 years ago