#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Google ReCaptcha - Classic ASP - ERROR


    Hello,

    I got someone to add Google ReCaptcha to a form, however since they have added it when you complete the form it doesn't submit the data to the database if the Captcha is correct.

    The added some code to the page which I think could be causing the error, please can you look at it and debug, if needed to pay someone to sort it I will but it needs fixing today:

    Response.write(Cstr(recaptcha_response_field))

    server_response = ""

    newCaptcha = True

    if (recaptcha_challenge_field <> "" or recaptcha_response_field <> "") then
    server_response = recaptcha_confirm(recaptcha_challenge_field, recaptcha_response_field)
    newCaptcha = False
    end if


    postToDB = False

    ' if form submitted
    if killChars(request.querystring("s")) = "t" then
    If Len(server_response)=0 then
    If newCaptcha=true then
    postToDB = true
    End if
    End if
    End if


    Response.write(Cstr(postToDB))

    if postToDB = True then
    ....
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,445
    Rep Power
    4539
    Post the complete error message you get, and identify the line of code that's generating the error.

    And use the forum CODE tags around posted code.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0
    I just found this code.. Put this on top of your asp page.. Just need some tweaks..
    Code:
    <%
      recaptcha_challenge_field  = Request("recaptcha_challenge_field")
      recaptcha_response_field   = Request("recaptcha_response_field")
      recaptcha_public_key       = "your_public_key" ' your public key
      recaptcha_private_key      = "your_private_key" ' your private key
    
      ' returns the HTML for the widget
      function recaptcha_challenge_writer()
    
      recaptcha_challenge_writer = _
      "<script type=""text/javascript"">" & _
      "var RecaptchaOptions = {" & _
      "   theme : 'red'," & _
      "   tabindex : 0" & _
      "};" & _
      "</script>" & _
      "<script type=""text/javascript"" src=""http://www.google.com/recaptcha/api/challenge?k=" & recaptcha_public_key & """></script>" & _
      "<noscript>" & _
        "<iframe src=""http://www.google.com/recaptcha/api/noscript?k=" & recaptcha_public_key & """ frameborder=""1""></iframe><>" & _
          "<textarea name=""recaptcha_challenge_field"" rows=""3"" cols=""40""></textarea>" & _
          "<input type=""hidden"" name=""recaptcha_response_field""value=""manual_challenge"">" & _
      "</noscript>"
    
      end function
    
      ' returns "" if correct, otherwise it returns the error response
      function recaptcha_confirm(rechallenge,reresponse)
    
      Dim VarString
      VarString = _
              "privatekey=" & recaptcha_private_key & _
              "&remoteip=" & Request.ServerVariables("REMOTE_ADDR") & _
              "&challenge=" & rechallenge & _
              "&response=" & reresponse
    
      Dim objXmlHttp
      Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
      objXmlHttp.open "POST", "http://www.google.com/recaptcha/api/verify", False
      objXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
      objXmlHttp.send VarString
    
      Dim ResponseString
      ResponseString = split(objXmlHttp.responseText, vblf)
      Set objXmlHttp = Nothing
    
      if ResponseString(0) = "true" then
        'They answered correctly
         recaptcha_confirm = ""
      else
        'They answered incorrectly
         recaptcha_confirm = ResponseString(1)
      end if
    
      end function
    
      server_response = ""
      newCaptcha = True
      if (recaptcha_challenge_field <> "" or recaptcha_response_field <> "") then
        server_response = recaptcha_confirm(recaptcha_challenge_field, recaptcha_response_field)
        newCaptcha = False
      end if
    
      %>
    And here's on the html part..
    Code:
      <html>
      <body>
    
      <% if server_response <> "" or newCaptcha then %>
    
        <% if newCaptcha = False then %>
    
          <!-- An error occurred -->
          Wrong!
    
        <% end if %>
    
        <!-- Generating the form -->
        <form action="recaptcha.asp" method="post">
          <%=recaptcha_challenge_writer()%>
        </form>
    
      <% else %>
    
        <!-- The solution was correct -->
        Correct!
    
      <%end if%>
    
      </body>
      </html>

IMN logo majestic logo threadwatch logo seochat tools logo