Greetings! Below is the comprehensive solution for client-side validation:
HTML form: I have included a text box called google-response and set up three callback events: 1) data-error-callback="wrongCaptcha", 2) data-callback="correctCaptcha", 3) data-expired-callback="wrongCaptcha".
<form class="form-inline" class="text-center">
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="newsletter-email" class="form-control" id="email">
</div>
<button type="button" class="btn btn-default" onclick="validationNewsletter()">Submit</button>
<input type="hidden" id="google-response"/>
<br/><br/>
<div class="form-group">
<div class="g-recaptcha" id="gcaptcha" data-sitekey="XXXX-XXXX" data-error-callback="wrongCaptcha" data-callback="correctCaptcha" data-expired-callback="wrongCaptcha"></div>
</div>
</form>
JS Validation
<script>
function validationNewsletter() {
if($('#google-response').val()==""||$("[name=g-recaptcha-response]").val()==""){
alert("Please check google recaptcha");
return false;
}
if($('#google-response').val()!=$("[name=g-recaptcha-response]").val()){
alert("Sorry spammer");
return false;
}
if(letsPutFormValidation){
alert("Some form validation");
return false;
}
$('#form-id').submit();
}
var correctCaptcha = function (response) {
$('#google-response').val(response);
};
var wrongCaptcha=function(response){
$('#google-response').val('');
}
</script>