The reCaptcha module provides built-in support for verifying Google reCAPTCHA tokens in your server-side code. It enables secure validation of user interactions to help prevent bots and abuse across your forms, sign-ups, and other public-facing endpoints.
This module is designed to work with reCAPTCHA v2 and v3 tokens, verifying them directly against Google's reCAPTCHA API. It handles token validation and response parsing, allowing you to easily incorporate bot protection into your pserver-side logic.
Note: The Recaptcha module is globally available in the SDK environment via kd.recaptcha.
By using kd.recaptcha, you ensure that only verified human users can proceed through public forms and pages of your application.
// Verify a reCAPTCHA token
var token = "03AGdBq26_HZ7j9C5WzSC-hv9d-9HSNW..."; // Token from client-side
var isValid = kd.recaptcha.siteVerify(token);
/* Sample Response:
true // Token is valid
*/
// Using the verification in form submission handling
function handleFormSubmission(formData, recaptchaToken) {
// First verify the reCAPTCHA
var isHuman = kd.recaptcha.siteVerify(recaptchaToken);
if (!isHuman) {
return {
success: false,
error: "CAPTCHA verification failed. Please try again."
};
}
// Proceed with form processing if verification passed
// ...process form data...
return {
success: true,
message: "Form submitted successfully"
};
}