Custom Hidden Field in Sitecore Forms

Custom Hidden Field in Sitecore Forms

I came across a scenario in Sitecore Forms where I needed to build a hidden field. The form is intended for employees, and when they access it, it should automatically recognize them and capture their name and email address upon submission.

Let’s get started.

Create the Hidden Field in Core DB

  • Navigate to /sitecore/client/Applications/FormsBuilder/Components/Layouts/PropertyGridForm/PageSettings/Settings

 

  • Create the HiddenField based on /sitecore/client/Business Component Library/version 2/Layouts/Renderings/Forms/Form/Form Parameters

 

  • Fill out the following fields – 
    • Details 

Sitecore-Forms-hidden-field.png 

    • Validation

Sitecore-Forms-hidden-field-2.png

 

    • Conditions

Sitecore-Forms-hidden-field-3.png

 

    • Advanced

Sitecore-Forms-hidden-field-4.png

 

Create a Custom Field Type

  • Inherit from the StringInputViewModel class to create a new view model for your hidden field.

 

Create the View for the Field

  • Define the HTML and JavaScript needed to render the hidden field and set its value.

 

Custom Submit Action

Let’s create a custom submit action and read the properties from formSubmitContext.

Let’s bind it to the Form’s Submit Action.

Sitecore-Forms-hidden-field-7.png

Now I’m able to drag and drop the hidden field into the Form. 

Make sure to publish the Form and its related items.

Sitecore-Forms-hidden-field-6-1.png

Hope this helps.

Happy Sitecoring!

Leave a Reply

Your email address will not be published. Required fields are marked *