reCAPTCHA form element bug



I am using Foundation Commerce for a project that I am working on, and have the below mentioned nuget package installed to use the Recaptcha element:

<package id="EPiServer.Forms.Samples" version="3.5.0" targetFramework="net472" />

But upon using the element I always get an "Invalid captcha value" error.

I then opened the assemblies to see what is the code behind this and I see an issue there. The RecaptchaElementBlock class has a GetSubmittedValue method which returns a null in all cases and that basically causes the element validation (RecaptchaValidator) to fail.

public override object GetSubmittedValue()
      return (object) (HttpContext.Current.Request.HttpMethod == "POST" ? HttpContext.Current.Request.Form : HttpContext.Current.Request.QueryString)[this.Content.GetElementName()];

The code above is trying to fetch the recaptcha response based on the element name, but if you look at the form sumission it uses "g-recaptcha-response" as the query string parameter and not the element name. I think this needs to be refactored in order for it to work.

Edited, Aug 07, 2020 14:11

Hi Siddharth

It might speed up the process, if you raise the bug as an issue in the package's GitHub repository. Or write to the support team. Or both.

In the mean-time you could copy the code from the repository (it's open source, no need to open assemblies) and fix the bug in your own solution.

Aug 07, 2020 15:02
Siddharth Gupta - Aug 07, 2020 20:38
Hi Stefan,

I will create a support ticket to keep a track of the status of the bug. And yes, I did fix this in my own solution. Also, I just saw that Valdis had suggested the same fix back in 2017.

Quite surprised this is not fixed/merged until now.

* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.