Sitecore Bug

[Fixed] Sitecore WFFM : Creates a duplicate field section upon submission when exceeded to 10 sections.

Posted on Updated on

As explained in Stackoverflow > Sitecore WFFM : Creates a duplicate field section upon submission.

I eventually raised the issue to Sitecore, and after quite while they provided a Sitecore bug fix for my issue. I’ve tested the patch and it’s working now.

Thank you for filling up the form

Moreover, the following patch should to be implemented:

  1. Put the attached library into the bin folder. Download here.  (Applicable only for v.8.0)
  2. In the App_Config/Include/Sitecore.Forms.MVC.config file, replace the following line:

From:

<processor patch:before=”processor[@type=’Sitecore.Mvc.Pipelines.Loader.InitializeGlobalFilters, Sitecore.Mvc’]”
type=”Sitecore.Forms.Mvc.Pipelines.AddCustomMetadataProvider, Sitecore.Forms.Mvc” />

To:

<processor patch:before=”processor[@type=’Sitecore.Mvc.Pipelines.Loader.InitializeGlobalFilters, Sitecore.Mvc’]”
type=”Sitecore.Support.Forms.Mvc.Pipelines.AddCustomMetadataProvider, Sitecore.Support.434449” />

 

Disassembling the Sitecore.Support.434449.dll to understand the root cause a little further

#1. Override the CreateModel of SectionModelBinder


namespace Sitecore.Support.Forms.Mvc.Controllers.ModelBinders
{
public class SectionModelBinder : Sitecore.Forms.Mvc.Controllers.ModelBinders.SectionModelBinder
{
protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)
{
IHasModelFactory hasModelFactory = controllerContext.Controller as IHasModelFactory;
FormModel formModel = (hasModelFactory != null) ? hasModelFactory.ModelFactory.GetModel() : null;
if (formModel == null)
{
return base.CreateModel(controllerContext, bindingContext, modelType);
}
int index = int.Parse(bindingContext.ModelName.Substring(bindingContext.ModelName.IndexOf('[') + 1, bindingContext.ModelName.IndexOf(']') - bindingContext.ModelName.IndexOf('[') - 1));
return formModel.Sections[index];
}
}
} 

#2. Modify the  AddCustomMetadataProvider class > virtual void process

namespace Sitecore.Support.Forms.Mvc.Pipelines
{
internal class AddCustomMetadataProvider
{
[UsedImplicitly]
public virtual void Process(PipelineArgs args)
{
ModelMetadataProviders.Current = new ModelTypeMetadataProvider();
ModelBinders.Binders.Add(typeof(SectionModel), new Sitecore.Support.Forms.Mvc.Controllers.ModelBinders.SectionModelBinder());
ModelBinders.Binders.Add(typeof(FieldModel), new FieldModelBinder());
}
}
}

 

Edited: 08.03.2016

Sitecore.Support.434449.dll can be dowloaded here.

 

Edited: 08.04.2016

In Sitecore version 8.1

The following patch should to be implemented:

  1. Put the attached library into the bin folder. Download here. (Applicable only for v.8.1)
  2. In the App_Config/Include/Sitecore.Forms.MVC.config file, replace the following line:

From:

<processor patch:before=”processor[@type=’Sitecore.Mvc.Pipelines.Loader.InitializeGlobalFilters, Sitecore.Mvc’]”
type=”Sitecore.Forms.Mvc.Pipelines.AddCustomMetadataProvider, Sitecore.Forms.Mvc” />

To:

<processor patch:before=”processor[@type=’Sitecore.Mvc.Pipelines.Loader.InitializeGlobalFilters, Sitecore.Mvc’]”
type=”Sitecore.Support.Forms.Mvc.Pipelines.AddCustomMetadataProvider, Sitecore.Support.434449.81” />