【问题标题】:Classic ASP Form and reCAPTCHA query经典 ASP 表单和 reCAPTCHA 查询
【发布时间】:2013-12-28 10:07:14
【问题描述】:

我正在尝试将 recaptcha 添加到下面的代码中,但我不能 :( 联系页面有点像这样。

提交.asp文件:

....
function checktheform(){
    var error_msg = "0";
    if (document.theform.user_lesseename.value==''){
        document.getElementById("lbllessee").style.color = "#fdc110";
        document.getElementById("user_lesseename").style.borderColor = "#fdc110";
        error_msg = "1";
    }
    else{
        ...
        return false;
    }
    else{
        document.getElementById("valid_msg").innerText = '';
        return true;
    }
}

...

<div id="valid_msg"></div>
<form name="theform" method="post" action="sendmail.asp" onSubmit="return checktheform();">
    <input type="hidden" name="sendmail" value="1">
    <table width="490" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td valign="top">
                 <table width="179" border="0" align="center" cellpadding="2" cellspacing="0" class="submit_air">
                     <tr valign="middle">
                          <td width="175" valign="top"><label id="lbllessee">1. Name of lessee:</label></td>
                     </tr>
                     <tr>
                      ...
                     </tr>
                     <tr>
                         <td valign="top" align="right"><input name="Submit" type="submit" class="form_sub" value="Send" style="cursor:pointer;" ID="Submit1"></td>
                     </tr>
                 </table>

我的问题是,我将如何添加验证码?或任何其他具有这种编码形式的验证码方法?我是否需要以某种方式添加 recaptcha 检查到 checktheform();功能 ?如果是的话..怎么样? 我试图添加简单的验证码,它只是从谷歌服务器渲染图像,但我的 DATA 通过忽略验证码字段的表单。

【问题讨论】:

    标签: forms validation asp-classic recaptcha


    【解决方案1】:

    我想你可以通过查看这个谷歌开发者页面https://developers.google.com/recaptcha/old/docs/asp更新链接)找到你的答案

    这建议了如何实现服务器端 recaptha 管理。

    这里是一个实现建议

    关于 submit.asp 文件:

    1) 将来自谷歌开发者页面的代码添加到挑战作者的顶部:

    recaptcha_public_key = "your_public_key" ' your public key
    
    Function recaptcha_challenge_writer()
        ...
    End Function
    

    2) 在输入按钮前添加下表行:

    <tr>
      <td valign="middle">
        <%=recaptcha_challenge_writer()%>
      </td>
    </tr>
    

    3) 无论你想添加什么代码来验证和显示错误信息,比如:

    <%
        errorMessage = Request("error")
        If (errorMessage <> "" Then
    %>
        <p class="error-message"><%=error%></p>
    <%  End If  %>
    ...
    <td style="<% If errorMessage<>"" Then Response.Write "color:red" %>">
    ...
    

    在您的 sendmail.asp 脚本中:

    1) 在顶部添加来自谷歌开发者页面的确认功能代码:

    recaptcha_private_key = "your_private_key" ' your private key
    
    Function recaptcha_confirm(rechallenge,reresponse)
        ...
    End Function
    

    2) 然后添加代码检查输入:

    <%
        user_lesseename = Request("user_lesseename")
        recaptcha_challenge_field  = Request("recaptcha_challenge_field")
        recaptcha_response_field   = Request("recaptcha_response_field")
        If (user_lesseename = "") Then
            Response.Redirect "caller.asp?error=" & Server.UrlEncode("Lesee name could not be empty")
        Else
            server_response = recaptcha_confirm(recaptcha_challenge_field, recaptcha_response_field)
            If (server_response <> "") Then
                Response.Redirect "caller.asp?error=" & Server.UrlEncode("Recaptcha value is not correct: " & server_response)
            End If
        End If
        'The input is validate continue with sendmail code
    %>
    

    如果您更喜欢管理 recaptcha 检查客户端,则应使用 AJAX,如 https://developers.google.com/recaptcha/docs/display#AJAX

    【讨论】:

    • 链接目前已损坏。
    • @NicholasPickering - 感谢您的提示,我找到了新链接并更新了答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-17
    • 1970-01-01
    • 2012-05-27
    • 2012-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多