Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Ajax form not working since grav-plugin-form 3.0.6-7

Started by ontime 7 years ago · 0 replies · 898 views
7 years ago

Since the update from grav-plugin-form 3.0.5, my ajax forms do not work as expected. I am not sure if this is caused by the plugin or by the way Grav manages languages.

This form worked as expected until the update:

YAML
title: 'Contact'
cache_enable: false
form:
    action: /contact
    name: contact-form
    template: form-messages
    refresh_prevention: true

With this JS:

JS
$.ajax({
    url: form.attr('action'),
    type: form.attr('method'),
    data: form.serialize(),
    dataType: 'html',
    success: function() {},
    beforeSend: function() {},
    complete: function(result) {}
});

When the website has multiple languages, and paths are prefixed with the language code, this code no longer works since the update. There is an issue with redirection.

I put in place a temporary fix by hardcoding one language to the action path:

YAML
form:
    action: /en/contact

It works, but it is not a good long-term solution: is this a bug of grav-plugin-form? Of Grav? Or is there a fundamentally better (and bug-free) way of submitting an ajax form in Grav?

Suggested topics

Topic Participants Replies Views Activity
General · by themetman, 23 hours ago
2 39 16 hours ago
General · by Hanns Mattes, 1 week ago
0 119 1 week ago
General · by Karmalakas, 1 week ago
2 184 1 week ago
General · by Hanns Mattes, 3 weeks ago
0 234 3 weeks ago
General · by Dima, 4 weeks ago
1 210 4 weeks ago