谷歌验证码隐形,验证

时间:2017-09-12 08:53:17

标签: jquery validation recaptcha captcha

当我将ajax验证码检查添加到表单验证脚本时,验证和验证码现在都不起作用。 你能说出我应该找错的地方吗?

   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

<?php
if(isset($_POST['g-recaptcha-response'])) {
    $secretKey = '6L---4Oyg';
    $response = $_POST['g-recaptcha-response'];     
    $remoteIp = $_SERVER['REMOTE_ADDR'];
    $reCaptchaValidationUrl = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$response&remoteip=$remoteIp");
    $result = json_decode($reCaptchaValidationUrl, TRUE);
    print_r($result);

    if($result['success'] == 1) {
        $userMessage = '<div>Success: you\'ve made it :)</div>';
    } else {
        $userMessage = '<div>Fail: please try again :(</div>';
    }
}
?>

0 个答案:

没有答案