Form not working any more

I am not sure what and when it happened, and if this has something to do with Forms 2.0, but the tell-a-friend form on my grav installation does not work any more. Once the fields are filled and the “Send” button is clicked, it just reloads the page and the email is not sent. Formerly it properly sent the email and showed the configured message.

I did not change anything in my installation since it was still working, I only kept my grav installation and its plugins up-to-date. I do not use a separate file for the form, nor do I use a separate “thankyou” page, I do it all from the main page file. The form is configured like this and is just displayed at the bottom of the page:

form:
    name: tell-a-friend
    fields:
        -
            name: sender_name
            label: 'Your Name'
            placeholder: 'Enter Your Name'
            type: text
            validate:
                required: true
        -
            name: friend_name
            label: 'Your Friend's Name'
            placeholder: 'E nter Your Friend's Name'
            type: text
            validate:
                required: true
        -
            name: friend_email
            label: 'Your Friend's Email Address'
            placeholder: 'Enter Your Friend's Email Address'
            type: email
            validate:
                required: true
    buttons:
        -
            type: submit
            value: Send
    process:
        -
            email:
                to: '{{ form.value.friend_email }}'
                bcc: '{{ config.plugins.email.from }}'
                subject: 'TeslaBargain.com - Recommended by {{ form.value.sender_name|e }}'
                body: 'Hello {{ form.value.friend_name|e }},</br></br>{{ form.value.sender_name|e }} would like to recommend our website to you:<h1><a href="http://teslabargain.com">http://TeslaBargain.com</a></h1>Check it out now!</br></br>--</br>Tesla Bargain - This Is How You Get Your Tesla Motors Discount'
        -
            message: 'Thank you for your recommendation!'

Can you paste the form within triple backticks, so it’s shown correctly?

OK, sorry, I though regular markdown is working here (overlooked the preview).

form:
    name: tell-a-friend
    fields:
        -
            name: sender_name
            label: 'Your Name'
            placeholder: 'Enter Your Name'
            type: text
            validate:
                required: true
        -
            name: friend_name
            label: 'Your Friend's Name'
            placeholder: 'Enter Your Friend's Name'
            type: text
            validate:
                required: true 
        -
            name: friend_email
            label: 'Your Friend's Email Address'
            placeholder: 'Enter Your Friend's Email Address'
            type: email
            validate:
                required: true
    buttons:
        -
            type: submit
            value: Send
    process:
        -
            email:
                to: '{{ form.value.friend_email }}'
                bcc: '{{ config.plugins.email.from }}'
                subject: 'TeslaBargain.com - Recommended by {{ form.value.sender_name|e }}'
                body: 'Hello {{ form.value.friend_name|e }},</br></br>{{ form.value.sender_name|e }} would like to recommend our website to you:<h1><a href="http://teslabargain.com">http://TeslaBargain.com</a></h1>Check it out now!</br></br>--</br>Tesla Bargain - This Is How You Get Your Tesla Motors Discount'
        -
            message: 'Thank you for your recommendation!'

Works fine to me, submits email and shows “Thank you for your recommendation”. Make sure you’re up to date with all plugins and Grav core.

Also I had to change all ' in the YAML which were conflicting with Friend's

Also check with Cache disabled, to see if that’s the problem

Did you try on my website?

No, I tried the form on my test site

The apostrophe in my YAML is actually written as & apos ;, so that’s not an issue. Grav core and all plugins are up to date. I’m trying with cleared cache and cache disabled now.

Nope, still doesn’t work with cache disabled.

I saw the site, it’s a modular form. Did you check Using forms in modular pages?

My website is not modular, it consists of a single page in a multi-language setup.

Your home page must be a modular page, as the form is just a component of it. Thus the rules of that article apply. I tested the form on a standalone form page and it worked fine.

Nope, my home page (and that’s the only page, just in different language versions) is definitely not a modular one, it is exactly setup as the first example on https://learn.getgrav.org/forms/forms

So I first have the header section enclosed in two --- with all that need to go in there, then the page content and the form is shown at the bottom of that page, exactly as in that example. I haven’t looked into modular pages, I assume I should have done it that way, but it was easier and faster for me to setup my page as is.

As said, it all worked before just fine, but now it doesn’t, and all that I have done is to regular upgrade the grav core and the installed plugins whenever I have seen that an update was available. I don’t really know what steps I should implement from “Using forms in modular pages” in that case.

In “Using forms in modular pages” it tells to copy over the template files from the Antimatter theme:

templates/form.html.twig
templates/formdata.html.twig

but I only have form.html.twig and not a formdata.html.twig in my Antimatter theme folder. Am I missing something here?

I’m sorry, I am currently completely lost with that issue. If anybody has any ideas what changed and how it can be fixed, I’d really appreciate it, otherwise I think I will just have to remove the form from my website.

Tried cache_enable: false in my page header and copied over templates/form.html.twig to my theme folder, but that also didn’t change anything.

I have played around with that problem the whole afternoon, but I can’t get it to work again. Looks like it’s time to give up on that form and remove it from my page. :frowning:

You mention different language versions, so might be an issue similar to https://github.com/getgrav/grav-plugin-form/issues/111 but the original user never replied so I could not replicate the problem. Anyway I have tested the form on a multilang site too.

If you can, send me your user/ folder zipped at https://gitter.im/flaviocopes to replicate with your exact same site configuration.

Yes, that issue # 111 seems to be exactly what I am experiencing in my setup.

I just took a look, but I am hesitant to upload my whole user folder. Which files do you need? Or asked the other way around, which files or what data should I delete before sending you my user folder, so that you are still able to test it but does not reveal sensitive data?

Exceptional, @flaviocopes already found the solution to that problem by setting redirect_trailing_slash: false

All working again! :slight_smile: