Squiz Custom Form - Call REST Resource Validation with Regex


(Mel Freeman) #1

Matrix Version: 5.5.6.4

Hi,

I’m using the Call REST Resource option on a Custom Form to do server side Google RECAPTCHA V2 validation.

I’ve enabled the Validation Rule, and would like to use regex to match two values in the response.

{  "success": true,  "challenge_ts": timestamp, "hostname": "myservername", "error-codes": [...] }

In the validation rule, when I just put in true, that works fine. If I put in myservername then that works fine.

When I put in /true(.)myservername/ or true(.)myservername without slashes then it fails validation.

I tried putting the regex through regex101 - my favourite regex checker, and I think it should work. Any tips specifically for this component in the Custom Form?

I am escaping dots in my servername in my regex. My problem is when I try to match true and the myservername.


(Mel Freeman) #2

Okay. I worked it out.

|.*true.*servername\.gov.*|i

(Bart Banda) #3

Good to hear you worked it out.

Curious to know why you are implementing your own check for this rather than using the built-in one that’s available on custom forms already?


(Mel Freeman) #4

Hi Bart, Two reasons. One, I wanted to use AJAX form submission. Two, the settings for Google RECAPTCHA are global, and I’m not the owner of the keys in the global settings.

Also, the documentation is a bit thin on the Google RECAPTCHA. I wasn’t sure exactly what it does/doesn’t do.


(Bart Banda) #5

Thanks for the extra insight Mel, the fact that you can’t/don’t want to use the global keys makes sense as a reason alone to roll with your own. We might look at the ability to use different keys for different sites/forms.