سؤال

I am trying to add recaptcha to the code below but i can't :( the contact page it's somethink like that.

submit.asp file :

....
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>

My question is , how i will add recaptcha? or any other captcha method with this coding form ? Do i need to add somehow recaptcha check to checktheform(); function ? and if yes..how ? I was try to add simple captcha which just render the image from google server, but my DATA passed the form ignoring the Captcha field.

هل كانت مفيدة؟

المحلول

I think you can find your answer giving a look to this google developers page https://developers.google.com/recaptcha/old/docs/asp (Updated Link)

this suggest how implement server side recaptha management.

Here an implementation suggestion

On the submit.asp file:

1) Add on the top the code from the google's developers' page for the challenge writer:

recaptcha_public_key = "your_public_key" ' your public key

Function recaptcha_challenge_writer()
    ...
End Function

2) add before the input button the following table row:

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

3) Whatever you want add code to verify and display error message, like:

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

In your sendmail.asp script:

1) Add on the top the code from the google's developers' page for the confirm function:

recaptcha_private_key = "your_private_key" ' your private key

Function recaptcha_confirm(rechallenge,reresponse)
    ...
End Function

2) then add the code to check the input:

<%
    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
%>

If you instead prefere to manage recaptcha checking client side you should use AJAX as illustrated in https://developers.google.com/recaptcha/docs/display#AJAX

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top