首頁  >  問答  >  主體

重新編寫的標題為:使用reCAPTCHA驗證 - 連線至登入按鈕

<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%>"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>
P粉809110129P粉809110129411 天前506

全部回覆(1)我來回復

  • P粉060112396

    P粉0601123962023-09-05 09:22:20

    全部排序

    #
    </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>

    回覆
    0
  • 取消回覆