具有优先级值的AJAX表单

时间:2016-09-20 09:38:22

标签: javascript php html ajax recaptcha

我想创建具有优先级值的表单,首先检查recaptcha的值是否正确(不是垃圾邮件发送者)然后执行处理,例如:

$('#Selection').on('change', function () {

if(this.value === "Section1"){
    $("#Section1").show();
} else {
    $("#Section1").hide();
}

  if(this.value === "Section2"){
    $("#Section2").show();
} else {
    $("#Section2").hide();
}

  if(this.value === "Section3"){
    $("#Section3").show();
} else {
    $("#Section3").hide();
}

  if(this.value === "Section4"){
    $("#Section4").show();
} else {
    $("#Section4").hide();
}

      if(this.value === "Section5"){
    $("#Section5").show();
} else {
    $("#Section5").hide();
}

和HTML代码如:

   if(isset($_POST['g-recaptcha-response']))
{
      $captcha=$_POST['g-recaptcha-response'];

}
    if(!$captcha)
        {
        echo "enter captcha";

    }

    $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=*******&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);

        if($response.success==TRUE){

            $name = $_POST['name'];

            if($name == "hello"){
                echo 'correct';
            }

        else {
                echo 'incorrect';
            }
        }


    if($response.success==false)
    {
        die("spammer!");

    }

<form id="form" method="POST" action=""> <input id="name" name="name" type="text"/> <div class="g-recaptcha-response" data-sitekey="******"></div> <input id="button" type="submit" value="send" /> </form> <div id="formresult"></div> 用于ajax回答

我写了一些脚本代码,但没有用,我更喜欢在这里没有粘贴代码的问题。我怎么能这样做?

0 个答案:

没有答案