Rewritten title: Authentication with reCAPTCHA - Connect to login button
P粉809110129
P粉809110129 2023-09-04 11:27:54
0
1
546
<p>I've been trying to implement reCaptcha in my little project. I added two scripts below the login validation form section and the reCaptcha is working fine but I want to remove one of the reCaptcha's "Submit" button and link it to the "Login" button. Can anyone help me? </p> <pre class="brush:php;toolbar:false;"></div> <div id="content"> <form action="Validation" method="post"> <table> <tr><td>Username:</td><td><input type="text" name="username" value="<%=user%>" / ></td></tr> <tr><td>Password:</td><td><input type="text" name="password" value="<%=pass%>"/> ;</td></tr> <tr><td><input type="submit" name="Login" value="Login"/></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="Submit" /> </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;">This field is required. </span>'; return false; } return true; } function verifyCaptcha(token) { recaptcha_response = token; document.getElementById('g-recaptcha-error').innerHTML = ''; } </script></pre> <p>I tried a few things but it didn't work for me. </p>
P粉809110129
P粉809110129

reply all(1)
P粉060112396

Sort all

</div>
        
        <div id="content">
<form action="Validation" method="post" onsubmit="return submitUserForm();">
    <table> 
        <tr><td>用户名:</td><td><input type="text" name="username" value="<%=username%>" /></td></tr>
        <tr><td>密码:</td><td><input type="password" name="password" value="<%=password%>"/></td></tr>
        
        <tr >
            <td colspan="2">
            <div class="g-recaptcha" data-sitekey="我的站点密钥" data-callback="verifyCaptcha"></div>
            <div id="g-recaptcha-error"></div>
            </td>
        </tr>
        <tr><td><input type="submit" name="Login" value="登录"/></td></tr>
    </table>  
        
</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>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template