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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

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

Started by ontime 7 years ago · 0 replies · 464 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 Jerry Hunt, 3 days ago
2 70 5 hours ago
General · by pamtbaau, 10 hours ago
1 45 9 hours ago
General · by Andy Miller, 22 hours ago
0 43 22 hours ago
General · by Marcel, 12 months ago
6 341 4 days ago
General · by Duc , 5 days ago
3 35 5 days ago