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 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看