简体   繁体   中英

Recaptcha in Form

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 ie 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\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>';
            }
        }

    }?>

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()">  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM