0
votes

I need help in validating the response of ReCaptcha in javascript validation which is made for other validations like, n Field is empty etc..

The javascript function function verify(f) {....} get called on onSubmit="return verify(this);" in html <form name="form2" method="POST" action="alink.asp" onSubmit="return verify(this);">

Bellow is the complete js function:

function verify(f) {
    var msg = '';
  var s = f.CKRoutingNumber.value;
  s = s.replace(/[^0-9]/gi, "");
  f.CKRoutingNumber.value = s;
  if (f.CustomerID.value == '') { msg = 'Please enter your Bricks R Us Customer ID.'; f.CustomerID.focus();  }
  else if (f.PurchaseOrderNumber.value == '') { msg = 'Please enter the purchase order number.'; f.PurchaseOrderNumber.focus();  }
  else if (f.Amount.value == '') { msg = 'Please enter the amount you wish to pay.'; f.Amount.focus();  }
  else if (f.CKBankName.value == '') { msg = 'Please enter a value into the Bank Name field.'; f.CKBankName.focus();  }
  else if (f.CKRoutingNumber.value == '') { msg = 'Please enter a value into the Routing Number field.'; f.CKRoutingNumber.focus();  }
  else if (s.length != 9) { msg = 'Please enter a valid nine-digit routing/transit number.'; f.CKRoutingNumber.focus();  }
  else if (f.CKAccountNumber.value == '') { msg = 'Please enter a value into the Account Number field.'; f.CKAccountNumber.focus();  }
  else if (f.CKNumber.value == '') { msg = 'Please enter a value into the Check Number field.'; f.CKNumber.focus();  }
  else if (f.BillingName.value == '') { msg = 'Please enter a value into the Full Name field.'; f.BillingName.focus();  }
  else if (f.BillingAddress.value == '') { msg = 'Please enter a value into the Billing Address field.'; f.BillingAddress.focus();  }
  else if (f.BillingCity.value == '') { msg = 'Please enter a value into the Billing City field.'; f.BillingCity.focus();  }
  else if (f.BillingState.value == '') { msg = 'Please select a value for the Billing State field.'; f.BillingState.focus();  }
  else if (f.BillingZIPCode.value == '') { msg = 'Please enter a value into the Billing ZIP Code field.'; f.BillingZIPCode.focus();  }
  else if (f.BillingPhone.value == '') { msg = 'Please enter a value into the Phone Number field.'; f.BillingPhone.focus();  }
  if (msg != '') {
    alert(msg);
    return false;
  }
}

The above function is on the same page in which the form is made.

Bellow is the ASP classic code which get response from reCaptcha. Its also on the same page

<%

Dim reresponse
reresponse= Request.form("g-recaptcha-response")

Dim VarString
VarString = _
          "?secret=6Lex3CMTAAAAAASVS5XnIq4Ya5ZGvEH_W70NU&amp;" & _
          "&response=" & reresponse  & _
  "&amp;&remoteip=" & Request.ServerVariables("REMOTE_ADDR") 

 Dim url
 url="https://www.google.com/recaptcha/api/siteverify" & VarString

  Dim objXmlHttp
  Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")

  objXmlHttp.open "POST", url, False
  objXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  objXmlHttp.send

  Dim ResponseString
  ResponseString = objXmlHttp.responseText
  Set objXmlHttp = Nothing

 If instr(ResponseString, "success" & chr(34) &": true")>0 then
 // do nothing
 else
 // Here I want to get this response message and validate it in the above javascript function.

 end if
%>

I'm confused that how can I get the response from asp and validate it in the verify(f) javascript function so that I also get alert message on submit button that the recaptcha is required and or incorrect.

My intention is to validate the reCaptcha response in same veryify javascript function which get called on submit and shows validation in alert()

Remember, both asp code and javascript code are in the same page.

Please ask if you also need my form html code

1
Remember, the VBScript and JavaScript being "in the same page" is totally irrelevant: the VBScript runs on the server, while the JavaScript is run by the client (the browser). - Martha

1 Answers

0
votes

Your verify() function is running locally and doing some input value checking/alerting is OK, but in any case you should check whatever comes from the browser on de server side. If you would send the ReCaptscha response back to that verify() function you undermine your security because your users could simple change that verify() function ...