Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load ColdFusion values from Form scope when name includes hyphen/dash

Tags:

coldfusion

We're upgrading to Google's reCaptcha and it adds a field with name "g-recaptcha-response" to the form during submit. We them need to verify the response to Google with code like this:

<cfhttp url="https://www.google.com/recaptcha/api/siteverify" method="post" result="captchaResult">
  <cfhttpparam type="formfield" name="secret" value="SECRET"> 
  <cfhttpparam type="formfield" name="response" value="#Form.g-recaptcha-response#"> 
  <cfhttpparam type="formfield" name="remoteip" value="#CGI.REMOTE_ADDR#"> 
</cfhttp>

However, the #Form.g-recaptcha-response# gives Element G is undefined in FORM.

Is there another way to reference Form scope to allow hyphens?

like image 576
Nic Cottrell Avatar asked Jan 29 '26 02:01

Nic Cottrell


1 Answers

That will give you an error if the form variable doesn't exist. Try this instead:

<CFSET Form.Response = "">
<CFIF StructKeyExists(Form, "g-recaptcha-response")>
   <CFSET Form.Response = form["g-recaptcha-response"]>
</CFIF>

I wrote a reCAPTCHA v2 UDF yesterday. I wanted to support sToken so I could use the same API key on multiple websites.

http://gist.github.com/JamoCA/c4e83ca402bd6175a1d7

like image 188
James Moberg Avatar answered Jan 31 '26 02:01

James Moberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!