如何使用javascript在页面上使用多个google captcha实例

时间:2018-02-17 11:13:27

标签: javascript jquery recaptcha

我想在页面上的两个表单上使用Google的CAPTCHA

我已经能够在我的页面上的两个表格上实施CAPTCHA

但是当我点击表单1时,表单2 会出错(因为表单2在同一页面上为空)

这是我对CAPTCHA的实施

<script src='https://www.google.com/recaptcha/api.js'>
</script>
<script type="text/javascript" language="javascript">
function cap(){
    var captcha_response = grecaptcha.getResponse();
    if(captcha_response.length == 0) { // Captcha is not Passed
        alert("Please use capatcha below");
        return false;
    } else { // Captcha is Passed
        return true;
    }
}
// ]]>
</script> 


<form action="<?php echo 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>" method="post" onSubmit="alert('Your request has been received, we will get back to you shortly.');">
    <input name="name" type="text" placeholder="Your Name" required>
    <input name="email" type="email" placeholder="Email Address" required>
    <input name="phone" type="number" placeholder="Phone" required>
    <input name="location" type="text" placeholder="Location" required>
    <input name="budget" type="text" placeholder="Budget Range" required>
    <textarea name="message" placeholder="Message Here..." required></textarea>
    <div class="g-recaptcha" data-sitekey="6LcR0EIUAAAAALqc0BtX8KhMa1_oeK14ssjFi7RG"></div>
    <button type="submit" onclick="return cap();" class="tran3s">Send Request</button>
</form>

我试图创建单独的函数cap和caps,但我仍然有相同的错误

请问如何在不同表格的页面上使用此CAPTCHA的两个实例而不互相触发?

0 个答案:

没有答案