我想在页面上的两个表单上使用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的两个实例而不互相触发?