Hello guys
I added recaptcha to my jquery validation of callback form. But neither validation nor captcha work now. I can send blank from.
As I understand I should check captcha (result) inside success function? Tried but can’t do it correctly. Maybe I should do smth more and youcan give some pieces of advice. Thanks a lot
jQuery(document).ready(function($) {
$('.myform').submit(function() {
var formInputs = $(this).find('.validate');
var errors = '';
$(formInputs).each(function() {
if($.trim(this.value) == '') {
fieldLabel = $(this).parent().find('span.label-text').html();
errors += '- ' + fieldLabel + '\n'; }
$.ajax({
type: "POST",
url: "/reCaptcha.php",
data: form.serialize(),
dataType: "json",
error:function(){
grecaptcha.reset(); },
success:function(result){
if(errors.length > 0) {
alert('You didn't fill:\n\n' + errors);
return false;
}else{ $('.submit-button').val('Sending');
$('.submit-button').attr('disabled', 'disabled');
return true;
}
}
});
recaptcha.php
jQuery(document).ready(function($) {
$('.myform').submit(function() {
var formInputs = $(this).find('.validate');
var errors = '';
$(formInputs).each(function() {
if($.trim(this.value) == '') {
fieldLabel = $(this).parent().find('span.label-text').html();
errors += '- ' + fieldLabel + '\n'; }
$.ajax({
type: "POST",
url: "/reCaptcha.php",
data: form.serialize(),
dataType: "json",
error:function(){
grecaptcha.reset(); },
success:function(result){
if(errors.length > 0) {
alert('You didn't fill:\n\n' + errors);
return false;
}else{ $('.submit-button').val('Sending');
$('.submit-button').attr('disabled', 'disabled');
return true;
}
}