Jquery 包括不可见的
我在回调表单中有验证部分Jquery 包括不可见的,jquery,validation,recaptcha,Jquery,Validation,Recaptcha,我在回调表单中有验证部分 jQuery(document).ready(function($) { $('.form').submit(function() { var formInputs = $(this).find('.validate'); var errors = ''; $(formInputs).each(function() { if($.trim(th
jQuery(document).ready(function($) {
$('.form').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';
}
});
if(errors.length > 0) {
alert('Feel:\n\n' + errors);
return false;
}
else
{
$('.submit-button').val('Wait please...');
$('.submit-button').attr('disabled', 'disabled');
return true;
}
});
});
我需要在那里添加google recaptcha invisible,并做了一些更改:
...
else {
$('.submit-button').val('Wait please...');
$('.submit-button').attr('disabled', 'disabled');
function get_action(form) {
var v = grecaptcha.getResponse();
if(v.length == 0) {
grecaptcha.reset(); }
else {
$.ajax({
type: "POST",
url: "/reCaptcha.php",
data: form.serialize(),
dataType: "json",
success : function(text){
if (text == "success"){
formSuccess();
} else {
formError();
submitMSG(false,text); } }
}); } }
} }); });
reCaptcha.php
<?php
if(isset($_POST['g-recaptcha-response'])) {
$result = json_decode(file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=6L---7O&response=$_POST["g-recaptcha-response"]&remoteip=$_SERVER["REMOTE_ADDR"]'), TRUE);
if($result['success'] == 1) {
console.log("Ok");
} else {
grecaptcha.reset();
}
}
?>