Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

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

Started by ontime 7 years ago · 0 replies · 675 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 jeremycherfas, 4 days ago
3 92 10 minutes ago
General · by Old Man Umby, 2 days ago
1 60 2 days ago
General · by Sebastian, 4 days ago
1 81 4 days ago
General · by Andy Miller, 2 weeks ago
0 216 2 weeks ago
General · by ready-4-IT, 6 months ago
1 716 3 weeks ago