2016-03-07 593 views
-1

相关格式:的Recaptcha验证失败:请检查验证码

 <script language="JavaScript" src="gen_validatorv4.js" type="text/javascript"></script> 
     <script src='https://www.google.com/recaptcha/api.js'></script> 
    <div id="contactform"> 
      <div id="details"> 
     <form method="POST" name="contactform" action="contact-form-handler.php"> 
      <p> 
       <label for='name'>Full name *:</label><br> 
       <input type="text" name="name"> 
      </p> 
      <p> 
       <label for='address'>Address *:</label><br> 
       <input type="text" name="address"> 
      </p> 
      <p> 
       <label for='unit'>Unit:</label><br> 
       <input type="text" name="unit"> 
      </p> 
      <p> 
       <label for='postal'>Postal code *:</label><br> 
       <input type="text" name="postal"> 
      </p> 
      <p> 
       <label for='email'>Email:</label> <br> 
       <input type="text" name="email"> 
      </p> 
      <p> 
       <label for='phone'>Telephone *:</label><br> 
       <input type="text" name="phone"> 
      </p> 
      <p> 
       <label for='date'>Preferred pickup date* :</label> <br> 
       <input type="date" name="date"> 
      </p> 
      <p> 
       <label for='time'>Preferred timeslot* :</label><br> 
       <span id="small">Please provide us with a 2 Hr time slot<br> (10% discount if we don't make it in time <strong>after we agreed</strong> on a timeslot</span><br> 
       <input type="text" name="time1"> to <input type="text" name="time2"> 
      </p> 
      </div> 
      <div id="products"> 

      <p><label for='itemsharp'>Items for sharpening:</label><br> 
       <textarea name="itemsharp"></textarea> 
      </p> 
      <p> 
       <label for='itemrepair'>Items for repair:</label><br> 
       <textarea name="itemrepair"></textarea> 
      </p> 
      <p> 
       <label for='comment'>Comment: </label><br> 
       <textarea name="comment"></textarea> 
      </p> 
      <div class="g-recaptcha" data-sitekey="[mysitekey]" data-theme="dark"></div> 
      <input class="button" type="submit" value="Submit"><br> 
     </form> 
      </div> 
     </div> 

的PHP:

<?php 
$errors = ''; 
$myemail = '[aperfectlyvalidemailadress]';//<-----Put Your email address here. 
if(empty($_POST['name']) || 
    empty($_POST['email']) || 
    empty($_POST['address']) || 
    empty($_POST['postal']) || 
    empty($_POST['date']) || 
    empty($_POST['time1']) || 
    empty($_POST['time2']) || 
    empty($_POST['phone'])) 
{ 
    $errors .= "\n Error: fields with a * are required"; 
} 


$name = $_POST['name']; 
$email_address = $_POST['email']; 
$address = $_POST['address']; 
$postal = $_POST['postal']; 
if(!empty($_POST['unit'])){ 
    $unit = $_POST['unit']; 
} 
$phone = $_POST['phone']; 
$date = $_POST['date']; 
$time1 = $_POST['time1']; 
$time2 = $_POST['time2']; 
$itemsharp = $_POST['itemsharp']; 
$itemrepair = $_POST['itemrepair']; 
$comment = $_POST['comment']; 

if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", 
$email_address)) 
{ 
    $errors .= "\n Error: Please provide a valid email address"; 
} 

     $captcha; 
     if(isset($_POST['g-recaptcha-response'])){ 
      $captcha=$_POST['g-recaptcha-response']; 
     } 
     if(!$captcha){ 
      echo '<h2>Please check the captcha form.</h2>'; 
      exit; 
     } 
     $secretKey = "[mysecretkeyisfilledinhere]"; 
     $ip = $_SERVER['REMOTE_ADDR']; 
     $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip); 
     $responseKeys = json_decode($response,true); 
     if(intval($responseKeys["success"]) !== 1) { 
      echo '<h2>You are spammer ! Get the @$%K out</h2>'; 
     } else { 

if(empty($errors)) 
{ 
    $to = $myemail; 
    $email_subject = "Sharpening request: $name"; 
    $email_body = "You have received a new sharpening request. ". 
    "From:\n Name: $name \n Email: $email_address \n Phone: $phone \n Address: $address $unit $postal \n \n Date: $date \n Between: $time1 and $time2 \n Items for sharpening: $itemsharp \n Items for repair: $itemrepair \n Comment: \n $comment "; 

    $headers = "From: [email protected]\n"; 
    $headers .= "Reply-To: $email_address"; 

    mail($to,$email_subject,$email_body,$headers); 
    //redirect to the 'thank you' page 
    header('Location: requestthankyou.html'); 
} 
     } 
?> 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
    <title>Request failed</title> 
</head> 

<body> 
<!-- This page is displayed only if there is some error --> 
<?php 
echo nl2br($errors); 
?> 


</body> 
</html> 

大部分是从各种来源拼凑。我的PHP不是那么强大。

我在第一次创建它时测试了它,它工作正常。

现在,该网站是生活和....没有。任何尝试提交表单都会导致“请检查验证码”错误页面。我没有改变一件事,这就是为什么我感到沮丧。

由于显而易见的原因,我在此屏蔽了电子邮件地址和密钥。

我已经看过其他问题,但他们要么不相关(使用不同的和不熟悉我的语言),或者我根本不明白我为此道歉。

任何帮助将不胜感激。

+0

您是否在控制台中看到任何错误?是否所有的文件加载好(再次,在网络控制台寻找404错误) – RamRaider

+0

我可以看到你的窗体中的一些任性的HTML标记〜你在表单内部和周围使用div标签的方式使得它无效narkup – RamRaider

+0

@RamRaider没有404错误。我同意div标签很奇怪,但它们是用于定位的目的。我想要两列,而不是一个长的形式。 – Ehlyah

回答

0

html表单存在明确的标记问题 - div标签打破了表单。

下面的标记看起来完全相同,但放心,form和div标记的prder已更改以确保窗体是vald。

<script language="JavaScript" src="gen_validatorv4.js" type="text/javascript"></script> 
<script src='https://www.google.com/recaptcha/api.js'></script> 
<div id="contactform"> 
    <form method="POST" name="contactform" action="contact-form-handler.php"> 
     <div id="details"> 
      <p> 
       <label for='name'>Full name *:</label> 
       <br> 
       <input type="text" name="name"> 
      </p> 
      <p> 
       <label for='address'>Address *:</label> 
       <br> 
       <input type="text" name="address"> 
      </p> 
      <p> 
       <label for='unit'>Unit:</label> 
       <br> 
       <input type="text" name="unit"> 
      </p> 
      <p> 
       <label for='postal'>Postal code *:</label> 
       <br> 
       <input type="text" name="postal"> 
      </p> 
      <p> 
       <label for='email'>Email:</label> 
       <br> 
       <input type="text" name="email"> 
      </p> 
      <p> 
       <label for='phone'>Telephone *:</label> 
       <br> 
       <input type="text" name="phone"> 
      </p> 
      <p> 
       <label for='date'>Preferred pickup date* :</label> 
       <br> 
       <input type="date" name="date"> 
      </p> 
      <p> 
       <label for='time'>Preferred timeslot* :</label> 
       <br> 
       <span id="small">Please provide us with a 2 Hr time slot<br> (10% discount if we don't make it in time <strong>after we agreed</strong> on a timeslot</span> 
       <br> 
       <input type="text" name="time1"> to 
       <input type="text" name="time2"> 
      </p> 
     </div> 
     <div id="products"> 
      <p> 
       <label for='itemsharp'>Items for sharpening:</label> 
       <br> 
       <textarea name="itemsharp"></textarea> 
      </p> 
      <p> 
       <label for='itemrepair'>Items for repair:</label> 
       <br> 
       <textarea name="itemrepair"></textarea> 
      </p> 
      <p> 
       <label for='comment'>Comment: </label> 
       <br> 
       <textarea name="comment"></textarea> 
      </p> 
      <div class="g-recaptcha" data-sitekey="[mysitekey]" data-theme="dark"></div> 
      <input class="button" type="submit" value="Submit"> 
      <br> 
     </div> 
    </form> 
</div> 
+0

太奇怪了。这解决了它。猜猜我在搞乱布局的时候搞砸了。非常感谢! – Ehlyah

+0

没问题 - 只要记住如果标记无效,则提交表单时可能会出现布局问题和未预见的问题 – RamRaider