Require User to click google's new recaptcha before form submission
You can check the textarea field with id g-recaptcha-response
. You can do as following:
$("form").submit(function(event) {
var recaptcha = $("#g-recaptcha-response").val();
if (recaptcha === "") {
event.preventDefault();
alert("Please check the recaptcha");
}
});
Hope this helps you.
A vanilla JavaScript implementation using parts of both Ankesh's and Lammert's solution:
var form = document.getElementById('ctct-custom-form');
form.addEventListener("submit", function(event){
if (grecaptcha.getResponse() === '') {
event.preventDefault();
alert('Please check the recaptcha');
}
}
, false);
Credit to for form submit listener code: How can I listen to the form submit event in javascript?
grecaptcha.getResponse()
-
Returns the response for the Recaptcha. You can check this in condition such as
grecaptcha.getResponse(opt_widget_id) === ""
Optional widget ID, defaults to the first widget created if unspecified.
Ref: https://developers.google.com/recaptcha/docs/display