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

Form not working any more

Started by Muut Archive 10 years ago · 18 replies · 1333 views
10 years ago

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:

YAML
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!'
10 years ago

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

10 years ago

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

YAML

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!'
10 years ago

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

10 years ago

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

10 years ago

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.

10 years ago

Nope, still doesn't work with cache disabled.

10 years ago

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

10 years ago

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.

10 years ago

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.

10 years ago

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.

10 years ago

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.

10 years ago

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. :(

10 years ago

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?

10 years ago

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

All working again! :)

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1350 9 years ago
Archive · by Muut Archive, 9 years ago
2 934 9 years ago
Archive · by Muut Archive, 9 years ago
2 4060 9 years ago
Archive · by Muut Archive, 9 years ago
1 2947 9 years ago
Archive · by Muut Archive, 9 years ago
3 1118 9 years ago