小编mil*_*edo的帖子

苦苦挣扎与recaptcha v2和表单提交

https://developers.google.com/recaptcha/docs/verify

if(isset($_POST['submit'])){
$recaptchaResponse = $_POST['g-recaptcha-response'];
$secretKey = 'MYKEY';
$request = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$recaptchaResponse);

    if(!strstr($request,"false")){
echo '<div class="notification error clearfix"><p><strong>Attention!</strong> You didnt complete the captcha.</p></div>';
exit();
Run Code Online (Sandbox Code Playgroud)

然后其余的php文件邮寄表单,但即使你没有完成recaptcha它也只是发送.基本上,如果JSON返回false,我希望它不会发送并显示错误

如果它有帮助,这里也是页面的形式,我也可能在那里做错了...

<form method="POST" action="post.php" name="contactform" id="contactform" class="container">

            <fieldset>
                <div class="form-field grid-half">
                    <label for="name">Name</label>
                    <span><input type="text" name="name" id="name" /></span>
                </div>
                <div class="form-field grid-half">
                    <label for="email">Email</label>
                    <span><input type="email" name="email" id="email" /></span>
                </div>
                <div class="form-field grid-full">
                    <label for="message">Message</label>
                    <span><textarea name="message" id="message"></textarea></span>
                </div>                  
                <div class="form-field grid-full">
                        <div class="g-recaptcha" data-sitekey="MYKEY"></div>
                </div>
            </fieldset>
            <div class="form-click grid-full">
                <span><input type="submit" name="submit" value="Submit" id="submit" /></span> …
Run Code Online (Sandbox Code Playgroud)

php forms json recaptcha

14
推荐指数
4
解决办法
3万
查看次数

标签 统计

forms ×1

json ×1

php ×1

recaptcha ×1