【问题标题】:Recaptcha in Form形式上的 Recaptcha
【发布时间】:2017-03-01 09:01:53
【问题描述】:

我的表单与给定的以下 URL 几乎相同:

网址:PHP form + Google reCAPTCHA

但是在答案中给出的我的网站(www.obzservices.com)中包含 PHP 代码后,我的网站只是向我显示了预加载器图标,即我的网站没有加载。我之前通过添加我的站点密钥、添加 $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>';
            }
        }

    }?>

【问题讨论】:

    标签: php recaptcha


    【解决方案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()">  
    

    【讨论】:

    • 我应用了这个,但是当我尝试时,即使没有解决验证码,我也能够提交表单。
    • 我已经更新了我的答案另外,你在哪里添加了 javascript ?
    • 在html上面添加这个
    • 我尝试在 和 之前添加 javascript。但在这两种情况下都失败了。我在上面编辑了我的 PHP 代码。请看一看。谢谢!
    • 请再次检查我的答案。
    猜你喜欢
    • 1970-01-01
    • 2017-08-29
    • 2017-08-25
    • 1970-01-01
    • 2012-06-29
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    • 2019-03-10
    相关资源
    最近更新 更多