经典ASP表单和reCAPTCHA查询

时间:2013-12-28 10:07:15

标签: forms validation asp-classic recaptcha

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

submit.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?或使用此编码形式的任何其他验证码方法?我是否需要以某种方式添加recaptcha check来检查表单();功能?如果是的话......怎么样? 我试图添加简单的验证码,它只是从谷歌服务器渲染图像,但我的数据传递的形式忽略了验证码字段。

1 个答案:

答案 0 :(得分:1)

我认为你可以找到你的答案,看看这个谷歌开发者页面https://developers.google.com/recaptcha/old/docs/asp更新后的链接

这表明如何实施服务器端的重新管理。

这是一个实施建议

在submit.asp文件中:

1)在Google的开发人员页面中为挑战编写者添加代码:

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)在google开发人员页面的顶部添加确认功能的代码:

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