包括recaptcha隐形

时间:2017-09-09 11:28:48

标签: jquery validation recaptcha

我有回调表单的验证部分

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隐形并进行一些更改:

              ...
                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();
    }
}
?>

验证仍然有效,但验证码不行。我尝试发送表格大约30次,并且没有显示验证码。问题出在哪里?

0 个答案:

没有答案