重新编写的标题为:使用reCAPTCHA验证 - 连接至登录按钮
P粉809110129
2023-09-04 11:27:54
<p>我一直在尝试在我的小项目中实现reCaptcha。我在登录验证表单部分下面添加了两个脚本,reCaptcha工作正常,但我想删除一个reCaptcha的“提交”按钮,并将其链接到“登录”按钮。有人能帮我吗?</p>
<pre class="brush:php;toolbar:false;"></div>
<div id="content">
<form action="Validation" method="post">
<table>
<tr><td>用户名:</td><td><input type="text" name="username" value="<%=user%>" /></td></tr>
<tr><td>密码:</td><td><input type="text" name="password" value="<%=pass%>"/></td></tr>
<tr><td><input type="submit" name="Login" value="登录"/></td></tr>
</table>
</form>
<form method="post" onsubmit="return submitUserForm();">
<div class="g-recaptcha" data-sitekey="My site key" data-callback="verifyCaptcha"></div>
<div id="g-recaptcha-error"></div>
<input type="submit" name="submit" value="提交" />
</form>
<script src='https://www.google.com/recaptcha/api.js'></script>
<script>
var recaptcha_response = '';
function submitUserForm() {
if(recaptcha_response.length == 0) {
document.getElementById('g-recaptcha-error').innerHTML = '<span style="color:red;">此字段为必填项。</span>';
return false;
}
return true;
}
function verifyCaptcha(token) {
recaptcha_response = token;
document.getElementById('g-recaptcha-error').innerHTML = '';
}
</script></pre>
<p>我尝试了一些方法,但对我没有起作用。</p>
全部排序