dphj737575 2016-01-30 21:57
浏览 36

JQuery验证和真人Captcha问题

I am trying to submit a form & am using jquery realperson for the captcha. The problem is the hash for the realperson field is not getting submitted. I want to validate the form including captcha and return the result on the same page whether successful or not.

Here is my example.html

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>jQuery Real Person</title>
<link rel="stylesheet" href="jquery.realperson.css">
<style>
label { display: inline-block; width: 20%; }
.realperson-challenge { display: inline-block }
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="jquery.plugin.js"></script>
<script src="jquery.realperson.js"></script>
<script src="jquery.validate.min.js"></script>
<script src="form-validate.js"></script>
<script>
$(function() {
$('#defaultReal').realperson();
});
</script>
</head>
<body>
<h1>Example</h1>
<p>&nbsp;</p>
<form action="formProcess.php" method="post" id="myForm" name="myForm">
<p><label>Other fields:</label><input type="text" id="field" name="field"></p>
<p><label>Please enter the letters displayed:</label>
    <input type="text" id="defaultReal" name="defaultReal"></p>
<p style="clear: both;"><label>&nbsp;</label><input type="submit" value="Submit"></p>
<div id="result"></div>
</form>
</body>
</html>

Here is my custom form submit:

    $.validator.setDefaults({
    submitHandler: function() {}
});

$(document).ready(function(){
            //form validation rules
            $("#myForm").validate({
                rules: {
                    field: "required"
                    },
                messages: {
                    field: "Please enter something"
                },
                submitHandler: function(form) {
                $("#result").html('');
                postForm();
             }

            });

function postForm() {
    var ajaxRequest;
    $("#result").html('');
    var values = $("#myForm").serialize()
    ajaxRequest= $.ajax({
            url: "formProcess.php",
            type: "post",
            data: values
        });

     ajaxRequest.done(function (response, textStatus, jqXHR){
          // show successfully for submit message
          $("#result").html(response);
     });

     /* On failure of request this function will be called  */
     ajaxRequest.fail(function (){
       // show error
       $("#result").html('There was an error!');
     });

    }


});

And my php processForm:

    <?php
function rpHash($value) {
    $hash = 5381;
    $value = strtoupper($value);
    for($i = 0; $i < strlen($value); $i++) {
        $hash = (leftShift32($hash, 5) + $hash) + ord(substr($value, $i));
    }
    return $hash; }

function leftShift32($number, $steps) {
    $binary = decbin($number);
    $binary = str_pad($binary, 32, "0", STR_PAD_LEFT);
    $binary = $binary.str_repeat("0", $steps);
    $binary = substr($binary, strlen($binary) - 32);
    return ($binary{0} == "0" ? bindec($binary) :
        -(pow(2, 31) - bindec(substr($binary, 1)))); 
}

if (rpHash($_POST['defaultReal']) == $_POST['defaultRealHash']) {

    echo "Security was Correct!";
}
else {
    echo "Security captcha incorrect!";
}

?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 谁有RH342练习环境
    • ¥15 STM32F407 DMA中断问题
    • ¥15 uniapp连接阿里云无法发布消息和订阅
    • ¥25 麦当劳点餐系统代码纠错
    • ¥15 轮班监督委员会问题。
    • ¥15 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
    • ¥20 关于变压器的具体案例分析
    • ¥15 生成的QRCode圖片加上下載按鈕
    • ¥15 板材切割优化算法,数学建模,python,lingo
    • ¥15 科来模拟ARP欺骗困惑求解