Sitecore Experience Forms Query string exception
Sitecore Experience Forms formerly known as Web Forms for Marketers (WFFM) allows Content Authors to construct web forms that record and report information provided by contacts on a website - ideally without the need for additional development.
The integrated nature of Sitecore Experience Forms requires some pipeline and HTTP life-cycle overrides specifically around GET and POST requests. This can lead to issues when dealing with partial query strings as Sitecore makes the assumption that all keys have a corresponding value - this is not the case nor is it enforced by many frameworks.
Placing a partial query string eg. /?sample into the URL for any page with a Sitecore form will cause the following exception:
Exception: System.ArgumentNullException Message: Value cannot be null. Parameter name: key Source: mscorlib at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer) at Sitecore.ExperienceForms.Mvc.Pipelines.RenderForm.SetFormParameters.Process(RenderFormEventArgs args) at (Object , Object ) at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
The exception above is thrown from the SetFormParameters pipeline located in the Sitecore.ExperienceForms.Mvc namespace as shown below:
It's attempts to parse the query string fail due to missing value parameters. This particular line also fails to map multiple values for a given key. By applying the changes below it can be updated to handle both partial and multiple query string cases: