Google以自定义形式重新收回

时间:2017-07-24 11:52:22

标签: wordpress forms recaptcha

我可以在选中或不选中框的情况下发送表格。 不知道从哪里开始。

我有一个接受电子邮件地址的“自定义”表单。 检查早期上传的.csv文件是否包含该特定电子邮件地址,并在.csv文件中发送与该电子邮件地址对应的电子邮件地址和数据集。

这一切都有效,但我需要添加一个reCaptcha函数。所以我想使用谷歌。

这是代码(没有检查和邮件功能)。基本形式

<form action="" method="post" enctype="multipart/form-data">
    <input type="text" name="field_name" />
    <div class="g-recaptcha" data-sitekey="6LcYnikUAAAAAMUyMmPRUlnnF-1i3pShj52unsn5"></div>
    <input type="submit" value="Versturen" />
</form>

标题包含:
<script src='https://www.google.com/recaptcha/api.js'></script>

更多信息:
- 处理电子邮件和文件检查的php在表单之后添加(也在表单之前尝试但没有区别)
- 我收到警告说它不能包含wp-load.php,但如果我发送表格,它会发送和发送。

Warning: include(../../../wp-load.php): failed to open stream: File or folder doesn't exist in /home/xxx/wp-content/themes/xxx/template.php on line 39

Warning: include(../../../wp-load.php): failed to open stream: File or folder doesn't exist in /home/xxx/wp-content/themes/xxx/template.php on line 39

Warning: include(): Failed opening '../../../wp-load.php' for inclusion (include_path='.:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php') in /home/xxx/wp-content/themes/xxx/template.php on line 39
第39行: include '../../../wp-load.php';

知道为什么reCaptcha不起作用?

1 个答案:

答案 0 :(得分:1)

需要验证.....
因为表单是自定义的,我需要实现验证。 形式:

<div>
    <form action="" method="post" id="FORMID" enctype="multipart/form-data">
        <input type="text" name="field_name" /><br />
        <div class="g-recaptcha" data-sitekey="==SITEKEY=="></div>
        <input type="submit" name="Submit" id="submit" value="Send" />
    </form>
</div>
<script src='https://www.google.com/recaptcha/api.js?hl=nl'></script>
        <script type="text/javascript">
        jQuery("#submit").click(function(e){
                var data_2;
            jQuery.ajax({
                        type: "POST",
                        url: "http://www.example.com/wp-content/themes/THEME/includes/google_captcha.php",
                        data: jQuery('#FORMID').serialize(),
                        async:false,
                        success: function(data) {
                         if(data.nocaptcha==="true") {
                       data_2=1;
                          } else if(data.spam==="true") {
                       data_2=1;
                          } else {
                       data_2=0;
                          }
                        }
                    });
                    if(data_2!=0) {
                      e.preventDefault();
                      if(data_2==1) {
                        alert("Check the captcha box");
                      } else {
                        alert("Please Don't spam");
                      }
                    } else {
                        jQuery("#FORMID").submit
                   }
          });
        </script>

google_captcha.php

<?php
$data;
header('Content-Type: application/json');
error_reporting(E_ALL ^ E_NOTICE);
if(isset($_POST['g-recaptcha-response'])) {
  $captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
  $data=array('nocaptcha' => 'true');
  echo json_encode($data);
  exit;
 }
 // calling google recaptcha api.

$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=KEYSECRET&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
 // validating result.
 if($response.success==false) {
    $data=array('spam' => 'true');
    echo json_encode($data);
 } else {
    $data=array('spam' => 'false');
    echo json_encode($data);
 }
?>