简体   繁体   English

如何在谷歌验证码中提供所需

[英]how to give required in google captcha

My PHP: 我的PHP:

include_once ('db.php');

$capt_err = '';
$error = 0;

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $message = $_POST['message'];
    $captcha = $_POST['g-recaptcha-response'];
    if (!$captcha) {
        echo '<script language="javascript">';
        echo 'alert("please check the captcha!");';

        // echo 'window.location.href="#mymodal";';

        echo '</script>';
        exit();
    }
    else {
        $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LcoHioTAAAAAHvJ0FIRLC-VWVmpBSs_-7igEkXh&response=" . $captcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']);
    }

    if ($response . success == false) {
        echo '<h2>You are spammer ! Get the @$%K out</h2>';
    }
    else {
        $result = mysqli_query($mysqli, "INSERT INTO vibodha_feedback (`id`,`name`,`email`,`phone`,`message`,`date`) VALUES('','$name','$email','$phone','$message',now())");
        echo "<script>" . "alert('Your Message has been sucessfully sent.')" . "</script>";
    }
}

// header('location:testimonials.php');

My HTML: 我的HTML:

<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>"  method="post">
    <fieldset>
        <label for="name">Name:</label>
        <input type="text" id="name" name="name" required>
        <label for="mail">Email:</label>    
        <input type="email" id="email" name="email" required>
        <label for="phone">Phone:</label>
        <input type="number" id="phone" name="phone" required>
        <label for="message">Message:</label>   
        <textarea id="message" name="message" required></textarea>
        <div class="g-recaptcha" data-sitekey="6LewHioTAAAAANGO-VChqdjsoZARTVOxsrgPW6T8"></div>
    </fieldset>
    <button type="submit">Send!</button>
</form>

My JavaScript: the script is default for g-recapcha(google),the google intergrate only recaptcha option..not to give required option. 我的JavaScript:该脚本默认为g-recapcha(google),google intergrate仅限recaptcha选项..不提供所需选项。

i wrote validation in php code.the captcha is empty alert will come(refer php code) 我在PHP代码中写了验证。验证码是空的警报将来(参考PHP代码)

the above three parts in my code..i give required in div class,,,the div not taken,then how to give required in captcha. 在我的代码中的上述三个部分..我在div类中给出了,,, div没有被采用,那么如何在captcha中提供所需。

Try something like this 尝试这样的事情

 <input type="text" class="inputcontact" id="captcha_contact" placeholder="Cod securitate" name="captcha" onchange="isEmpty('captcha_contact', 'hiba-captcha_contact')">
                <div id="error-captcha_contact"><span style="font-size: 8px;"></span></div>

JS file: JS档案:

        jQuery(document).ready(function () {
            jQuery('#contact_send').click(function () {
var minden_ok = true;
             if (minden_ok == true) {
                    minden_ok = isEmpty('captcha_contact', 'error-captcha_contact');
                }
 if (minden_ok == true) {
    //your code here
  }
        });



function isEmpty(ID, errorID) {
var value= jQuery('#' + ID).val();
if (value.length > 0) {
    jQuery("#" + errorID).hide("slow");
    jQuery("#" + ID).css("border-color", "");
    return true;
} else {
    jQuery("#" + errorID + " span:first").text("Please fill !");
    jQuery("#" + ID).css("border-color", "red");
    jQuery("#" + errorID).show("slow");
    jQuery("#" + ID).focus();
    return false;
}

You can get it by $_POST['g-recaptcha-response']; 你可以通过$ _POST ['g-recaptcha-response']得到它;

like 喜欢

include_once ('db.php');

$capt_err = '';
$error = 0;

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $message = $_POST['message'];
       if($_POST['g-recaptcha-response']=='') 
       {
       echo '<script language="javascript">';
        echo 'alert("please check the captcha!");';

        // echo 'window.location.href="#mymodal";';

        echo '</script>';
        exit();
       }

    else {
        $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LcoHioTAAAAAHvJ0FIRLC-VWVmpBSs_-7igEkXh&response=" . $captcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']);
    }

    if ($response . success == false) {
        echo '<h2>You are spammer ! Get the @$%K out</h2>';
    }
    else {
        $result = mysqli_query($mysqli, "INSERT INTO vibodha_feedback (`id`,`name`,`email`,`phone`,`message`,`date`) VALUES('','$name','$email','$phone','$message',now())");
        echo "<script>" . "alert('Your Message has been sucessfully sent.')" . "</script>";
    }
}

// header('location:testimonials.php');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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