2017-07-24 123 views
-1

我可以發送帶或不帶檢查框的表單。 不知道該去哪裏。Google recaptcha以自定義格式

我有一個接受電子郵件地址的「自定義」表單。 檢查早期上載的.csv文件是否有特定的電子郵件地址,併發送與.csv文件中該電子郵件地址對應的電子郵件地址和數據集。

這一切都有效,但我需要添加一個reCaptcha函數。所以我想用Google。

這裏是代碼(沒有檢查和郵件功能)。基本形式

<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將無法正常工作?

+0

你好互動,你可以添加一些JavaScript,能夠幫助您輕鬆的形式工作。請參閱此答案:https://stackoverflow.com/questions/29612879/google-recaptcha-how-to-make-required/29613089#29613089 – colecmc

+0

想通了。我沒有執行驗證。現在感覺真的很愚蠢。 Thnx tho' – Interactive

回答

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); 
} 
?>