表格中的Recaptcha

时间:2017-03-01 09:01:54

标签: php recaptcha

我的格式与以下网址几乎相同:

网址:PHP form + Google reCAPTCHA

但是在将PHP代码包含到我的网站(www.obzservices.com)后,我的网站只显示了预加载器图标,即我的网站没有加载。我之前通过添加我的站点密钥,添加$ name,$ title,$ location等编辑我的PHP代码,但它没有帮助。这是我的PHP代码:

<?php

    $name = $_POST['name'];
    $email = $_POST['email'];
    $title = $_POST['title'];
    $location = $_POST['location'];
    $industry = $_POST['industry'];
    $quantity = $_POST['quantity'];
    $message = $_POST['message'];
    $from = 'From: QuoteForm';
    $to = 'obaid@obzservices.com';
    $subject = 'Quote Request';

    $body = "From: $name\n E-Mail: $email\n Title: $title\n Location: $location\n Industry: $industry\n Quantity: $quantity\n Message:\n $message";


    if ($_POST['submit']) {
        if ($email != '') {
            if(mail ($to, $subject, $body, $from)) {
                echo '<p>Your message has been sent!</p>';

            } else {
                echo '<p>Something went wrong, go back and try again!</p>';
            }
        }

    }?>

1 个答案:

答案 0 :(得分:1)

添加以下simpleScript

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

   function get_action(form) 
 {
 var v = grecaptcha.getResponse();
  if(v.length == 0)
   {
document.getElementById('captcha').innerHTML="You can't leave Captcha Code empty";
return false;
 }
  else
  {
document.getElementById('captcha').innerHTML="Captcha completed";
return true; 
}
    }

</script>

并在提交按钮之前添加此HTML:

 <span id="captcha" style="color:red" /></span> 
<div class="g-recaptcha" id="rcaptcha"  data-sitekey="site key"></div>

将此添加到表单

onSubmit="return get_action()" such  As below
  <form action="" method="post" onSubmit="return get_action()">