I am confused about how forms are supposed to be configured.
Do I need to use “cache_enable: false” on the form itself?
The problem I have is that often the site gets stuck on the “thankyou” page. I created an order form with a thankyou page, just like the contact form (the site now has two form pages total), however this new form is not behaving. Many times the thankyou page does not show after submission, and other times it does but then it gets stuck there, even if I navigate away and go back to the order form from the navbar. So something is up with caching I’m guessing but it’s not clear to me what the best practice actually is. Examples show “cache_enable: false” on the thankyou page but not the form itself. Can someone explain this pattern to me?
I really could use some help on this. I am getting a bit crazed trying to figure out why my form does not behave properly. It does two things:
- Does not go to the thankyou page after submission most of the time.
- When it does go to the thankyou page, it gets stuck on it, no matter how I adjust the cache settings. I cannot reload and get the form again.
I’ve followed the guidelines for basic forms, and under “process” it looks like this:
process:
email:
subject: '[Order Form] {{ form.value.name|e }}'
body: '{% include ''forms/data.html.twig'' %}'
message: 'We will contact you to confirm soon.'
display: thankyou
I removed the “save” part since I don’t want local files to be created from the form.
For the oder form, I’ve tried adding “cache_enable: false” but that didn’t help so I removed it again. Only the thankyou page has that, as shown in the docs.
I tried enabling debugging for both the order form and the thankyou page, but nothing shows when submitting.
All I want is:
- The form sends the email and shows the thankyou page.
- If I reload, or navigate away and return, the form shows again.
Advice would be appreciated!
There must be something else which is preventing normal Form behaviour.
You could disable non essential plugins (other than Login, Forms, Problems and Admin if you’re using the Admin plugin). Does the thankyou page work if you leave out the email sending? Can you try with another fresh Grav install? Are you using a third party or custom theme?
Those are the things you should consider and try. Good luck!
1 Like
Nothing I do fixes this problem and it is causing big problems for us. It’s making me start to doubt Grav. I have been unable to debug the problem, even with error logging and debugging turned on. I get no logs, and when I submit the form, the debug bar goes away and won’t come back. If I touch the form it may break, but not in a logical / predictable way.
The site is on the latest Grav with up-to-date plugins, and the theme is a Grav one called “Woo” which was last updated a year ago. I copied the theme after that last update to it, and have changed much styling, that’s all.
The expected result is: I submit the form, it goes to the “thank you” page, and if I reload the browser the form shows again.
There are two possible bad outcomes after submit, and the behavior switches between them:
- The form clears and does not go to the Thank You page.
- The form goes to the Thank You page, but you can never go back to the form (not by reloading, and not by navigating around - you have to manually clear the cache from the admin tool).
Here is what the page’s yaml looks like - if you see anything wrong about it please let me know:
title: Order
published: true
body_classes: order
cache_enable: false
form:
name: order
fields:
directions:
type: display
label: 'Order to be delivered to your door!'
markdown: true
content: 'After you fill out this form, we will contact you to confirm your order.'
name:
label: Name
placeholder: 'Enter your name'
type: text
validate:
required: true
email:
label: Email
placeholder: 'Enter your email address'
type: email
validate:
required: true
address1:
label: 'Address Line 1'
type: text
validate:
required: true
address2:
label: 'Address Line 2'
type: text
validate:
required: false
city:
label: City
type: text
validate:
required: true
phone:
label: Phone
type: text
validate:
required: true
choose:
type: display
label: Flavors
markdown: true
content: 'Specify how many jars of each flavor:'
flavor-one:
label: 'One - $7'
type: number
placeholder: '# of jars'
flavor-two:
label: 'Two - $7'
type: number
placeholder: '# of jars'
flavor-three:
label: 'Three - $7'
type: number
placeholder: '# of jars'
day:
label: 'Day of Delivery (Friday July 17, Saturday July 18)'
type: date
validate:
min: '2020-07-17'
max: '2020-07-18'
required: true
buttons:
submit:
type: submit
value: Submit
reset:
type: reset
value: Reset
process:
save:
fileprefix: order-
dateformat: Ymd-His-u
extension: txt
body: '{% include ''forms/data.txt.twig'' %}'
email:
subject: '[Order Form] {{ form.value.name|e }}'
body: '{% include ''forms/data.html.twig'' %}'
message: 'We will contact you to confirm soon.'
display: thankyou
@Wartybliggens, I have run your form in a default fresh Grav 1.6.26 installation and it works as expected.
It shows the exact same behaviour as the Contact Form example from the documentation.
The form goes to the Thank You page, but you can never go back to the form (not by reloading […]
Both your form and the Contact Form show an alert warning for the re-submission of the data when reloading the page containing the thankyou message. Is this behaviour what you mean with “can never go back to the form (not by reloading […]”?
[…] and not by navigating around - you have to manually clear the cache from the admin tool).
I cannot reproduce this behaviour. Navigating back works (form not cleared as expected) and going back via menu-items works (form is cleared as expected).