Sitecore Experience Forms Query String Exception
Running into query string errors with Sitecore Experience Forms? This guide explains why incomplete or multi-value query strings cause failures and provides a working solution to handle them safely using a custom pipeline processor.
Sitecore Experience Forms, previously known as Web Forms for Marketers (WFFM), enables content authors to build forms that collect and report contact data without requiring additional development.
However, due to its tight integration with Sitecore pipelines and the HTTP request lifecycle, Experience Forms introduces custom handling for GET and POST requests. This leads to issues when processing partial query strings, as Sitecore assumes all query string keys have corresponding values—a behavior not enforced by many web frameworks.
For example, visiting a URL with a partial query string such as /?sample
on a page containing a Sitecore form results in 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)
This exception originates from the SetFormParameters
pipeline in the Sitecore.ExperienceForms.Mvc
namespace, where query string parsing fails due to missing values. The default implementation also does not handle multiple values for the same key as shown below:
Resolving the Issue
To address this, create a custom processor to replace the default SetFormParameters
behavior. The updated implementation safely handles both missing values and multiple values for a given key.