November Happy Hour will be moved to Thursday December 5th.

Episerver Forms multiple issues on Form Submit, subsequent page reloads with the form and recaptcha block

Vote:
 

Issue 1: Form on first submit, displays form submission completed with form fields still shown rather hidden. 

Issue 2: Form on page reload throws 500 exception where the exception throw with the message below , where the currentBlock on subsequent page reload return null. 

System.Web.HttpException
  HResult=0x80004005
  Message=Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

Inner Exception 1:
EPiServerException: ContentReference: Input string was not in a correct format.

Issue 3: 

After installing RecaptchaBlock via Episerver.Forms.Samples, getting 400 on scripts 

"https://www.google.com/recaptcha/api.js?render={0}", SiteKey

And I am using Recaptcha V2 TickBox

Please help me out in overcoming these issues

#259464
Jul 26, 2021 7:45
Vote:
 

For issue 1 - there seem to be a bug in the form handler on the server side, there is a field controlling  the multi-step forms that get set to -1 instead of 0 after posting the form once, we solved it like so:

    /// <summary>
    /// This circumvent a bug where the second time a form is posted, the __FormCurrentStepIndex value is -1, instead of the default 0, which causes an error in the data submit function.
    /// </summary>
    public class  CustomDataSubmissionService : EPiServer.Forms.Core.Internal.DataSubmissionService
    {
        public override SubmitActionResult PerformDataSubmit(NameValueCollection rawSubmittedData, HttpContextBase httpContext, ControllerBase controller)
        {   
            // the incoming collection is readonly, copy it
            var col = new NameValueCollection(rawSubmittedData);
            
            // the current form step should never be -1, so set it to 0 if it is submitted as such
            if(col["__FormCurrentStepIndex"] == "-1") {
                col["__FormCurrentStepIndex"] = "0";
            }

            return base.PerformDataSubmit(col, httpContext, controller);
        }
    }

And then use the custom service in your service container setup:

context.Services.RemoveAll<DataSubmissionService>();
context.Services.AddSingleton<DataSubmissionService, CustomDataSubmissionService>();
#261438
Sep 01, 2021 9:42
Vote:
 

Thanks for this solution!

#263405
Sep 20, 2021 12:20
* 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.