Cockpit Next reCAPTCHA

I really need to integrate reCAPTCHA v2 into my Cockpit form (using PHP) because my clients are collecting tons of spam. The unofficial add-on does not work with the latest versions of Cockpit. Can anyone help me with how to validate reCAPTCHA? Front end is easy to integrate but I’m struggling with the server side.

Thanks so much!!

Don’t know if you are still looking or have given up but I just came across this (last commit was only 11months ago so am hopefull!): https://github.com/jimmytricks/Cockpit-with-cURL-and-ReCAPTCHA

About to test it and see how it goes… I’ll update this post / add another comment once I know more!

Nope - can’t figure it out :frowning:
Being able to use recaptcha is such a basic necessity… really needs to be built into forms module. I think we just give up and use some other handler

Yeah, I wasn’t able to figure it out then moved on. Thanks for trying and updating this!

You probably don’t need it any longer but for anyone coming here from the search or from Google:

We had the same issues and wrote a small Cockpit Addon ourselves.
You can get it from gitlab.com/consulting-group-esslingen/cockpit-addons/cockpit-recaptcha

1 Like

This is awesome. Thank you!

thank you. it is important to improve cockpit with help of community.
i didnt quite understant which endpoint i need to send the form.
is it “/api/forms/submit/recaptcha_server_key”
do you have any example somewhere ?

You can submit your form to the regular endpoint of Cockpit, just include the recaptcha-response with the other data you are sending like so:

let data = {
    field1: 'value1',
    field2: 'value2',
    'g-recaptcha-response': grecaptcha.getResponse()
};

fetch(`YOUR-COCKPIT-URL/forms/submit/YOUR-FORM-ID?token=YOUR-API-TOKEN`, {
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ form: data })
}).then(entry => entry.json()).then(entry => {
    if (entry.errors || entry.error) {
        console.log(entry);
    } else {
        // SUCCESS
    }
});

Also check the Cockpit Forms Doc here and the Forms API Doc here.

1 Like

thank you for explanation. it is working now :slight_smile: