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.
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.