Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AJAX forms do not work anymore with captcha #512

Open
kaphadley opened this issue Mar 14, 2021 · 7 comments
Open

AJAX forms do not work anymore with captcha #512

kaphadley opened this issue Mar 14, 2021 · 7 comments
Assignees
Labels

Comments

@kaphadley
Copy link

Hi,

AJAX forms (as described in the documentation) do not work anymore when the form contains a type: captcha field.

Ajax and captcha work fine wight grav-plugin-form v3.0.8, but fails from at least v4.0.0.

@marcocevoli
Copy link

Same issue here.

@rhukster
Copy link
Member

we'll take a look at this...

@dledanseur
Copy link

This is due to the captcha integration bypassing our own event handlers by submitting the form. As a workaround, you can override the form's submit function. For instance, adapting the documentation:

const form = document.querySelector('#ajax-test-form');
form.submit = function() {

    const result = document.querySelector('#form-result');
    const action = form.getAttribute('action');
    const method = form.getAttribute('method');

    fetch(action, {
        method: method,
        body: new FormData(form)
    })
    .then(function(response) {
        if (response.ok) {
            return response.text();
        } else {
            return response.json();
        }
    })
    .then(function(output) {
        if (result) {
            result.innerHTML = output;
        }
    })
    .catch(function(error) {
        if (result) {
            result.innerHTML = 'Error: ' + error;
        }

        throw new Error(error);
    });
}

@kaphadley
Copy link
Author

@dledanseur your code is the same as the one from the documentation, except the missing event.preventDefault();. How is it supposed to solve the issue?

@dledanseur
Copy link

@dledanseur your code is the same as the one from the documentation, except the missing event.preventDefault();. How is it supposed to solve the issue?

Not exactly the same, the key point here is to override the form's submit function with form.submit =

@marcocevoli
Copy link

Any news about this. We're getting loads of spam because we needed to disable the captcha...

@01Kuzma
Copy link

01Kuzma commented Oct 3, 2022

More than a year has passed since the last answer... Spam is a real problem. Any news?
Moreover it doesn't work with dropzone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants