Sitecore Forms: How to change the id attribute

Subscribe to my newsletter and never miss my upcoming articles

Do you want to change the way Sitecore Forms generates ids or any attributes? Then follow through this short post.

Create a new class extending Sitecore.Mvc.Pipelines.MvcPipelineProcessor with the type Sitecore.ExperienceForms.Mvc.Pipelines.RenderForm.RenderFormEventArgs.

Add the following code:

Changing the id can break the Forms functionality. That’s why we need to create a hidden field to work this around.

Create a new class named CreateHiddenFields and add the following code:

Finally, add a config file patching to the forms.renderForm pipeline right after the processor Sitecore.ExperienceForms.Mvc.Pipelines.RenderForm.SetFormId, Sitecore.ExperienceForms.Mvc.

This way you can change how Sitecore Forms generates the id attribute.

image.png

Update July 24, 2020

Rodrigo has shared his complete code on changing the Form’s id. He tackled all the side effects and bugs. Please, check this out http://blog.peplau.com.br/en_US/bug-free-custom-form-ids-in-sitecore-forms.

Credits

Thanks Rodrigo for providing most of the sample code and finding about the breaking changes when you modify the form id.

Photo by Florian Olivo on Unsplash.

No Comments Yet