Hi there,
I´m new on Grav and tried to build a contact form in a modular page following the instructions “How to - Forms in a modular page” and “Frontend forms”.
I use the agency theme. The form is showing up on the modular page and I can fill in everything, but there is no email sent, no data saved and I´m not sent to the Thankful page.
I built a contact page as a regular page, too, and there everything works fine.
Since the form shows up in the modular page I think there must be something wrong with the processing, even though I copied it from the working regular page.
Does anybody has an idea to fix this?
Thanks a lot!
If you copied the form to a modular page, make sure you set cache_enable: false in the modular page’s frontmatter. Here’s a working modular form example saved as 01._form/form.md:
title: Contact Form
form:
name: contact-form
fields:
name:
label: Name
size: small
placeholder: 'Enter your name'
autofocus: true
autocomplete: true
type: text
validate:
required: true
email:
label: Email
size: small
placeholder: 'Enter your email'
type: email
validate:
required: true
buttons:
submit:
type: submit
value: Submit
process:
ip:
label: User IP Address
save:
filename: csvdata.txt
operation: add
body: "{% include 'forms/data.txt.twig' %}"
message: 'Thank you from your Feedback!'
redirect: /form/landing
cache_enable: false
# Contact Form
Contact form!!!
NOTE: I added a space in front of the --- so it would render in this forum software, they should be flush left
The main page´s modular.md contains the following:
title: '4 Wheel Drive'
content:
items: '@self.modular'
order:
by: default
dir: asc
custom:
- _header
- _the-band
- _the-musicians
- _the-music
- _discography
- _shop
- _videos
- _pictures
- _reviews
- _platzhalter
- _contact
title: Contact Form
form:
name: contact-form
action: /home
fields:
- name: name
label: Name
classes: form-control
placeholder: Enter your name
autofocus: on
autocomplete: on
type: text
position: left
validate:
required: true
- name: email
label: Email
classes: form-control
placeholder: Enter your email address
type: email
position: left
validate:
required: true
- name: message
label: Message
placeholder: Enter your message
type: textarea
classes: form-control
position: right
validate:
required: true
buttons:
- type: submit
classes: "btn btn-primary btn-lg"
value: Submit
process:
-
email:
subject: '[Site Contact] {{ form.value.name|e }}'
body: '{% include ''forms/data.html.twig'' %}'
-
save:
fileprefix: contact-
dateformat: Ymd-His-u
extension: txt
body: '{% include ''forms/data.txt.twig'' %}'
-
message: 'Thank you for getting in touch!'
-
display: thankyou
The form appears on the website but after filling it out and press the submit bottom there is no email sent, no data saved and one is not sent to the thankyou page or you get this:
First, remove email from the process. display too. Start with a bare bones form that saves to file.
I copied your modular.md and recreated your file structure, it works fine to me. Make sure you have the latest version of everything, and disable the pages cache to start with.
thanks to both of you. I tried hard to fullfill your tipps, but nothing changed. I read the GRAV documentation´s “How to: Forms in modular pages” agian and stumbled over this:
The path to the form.html.twig and the formdata.html.twig go to the templates-folder.
I had put them into a modular-subfolder, because otherwise I couldn´t set the modular-page-template in the Admin-Panel.
So I found I the following:
When I move both html.twigs out of the subfolder directly into the templates folder, the message from the form on my website is stored and I get an email sent. That´s fine!!! (even though I´m still not sent to the thankypue page).
And I can´t save changes on the form pages in the Admin-panel, since the page-template is automatically set to default, which would kill my form on the website totally.
I can´t choose the form- or formdata-template anymore, because these stuck in the templates-folder and not in the templates/modular-folder.
Is there a way to change the path to the form- and formdata.html.twig to the templates/modular -folder instead of the templates -folder?