douchibu7040 2017-03-01 09:01
浏览 45
已采纳

表格中的Recaptcha

I have almost the same form as given the following URL:

URL: PHP form + Google reCAPTCHA

But after including the PHP code to my website-(www.obzservices.com) given in the answer, my website is just showing me the pre-loader icon i.e. my website is not loading up. I have edit my PHP Code previously by adding my Site Key, adding $name, $title, $location etc but it didn't help. Here is my PHP code:

<?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
 E-Mail: $email
 Title: $title
 Location: $location
 Industry: $industry
 Quantity: $quantity
 Message:
 $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条回答 默认 最新

  • donglian4464 2017-03-01 10:03
    关注

    Add following 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>
    

    and add this HTML before your submit button:

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

    Add this to your form

    onSubmit="return get_action()" such  As below
      <form action="" method="post" onSubmit="return get_action()">  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?