Save Custom MVC forms data onto Sitecore Experience Forms Database

Reading Time: 5  min
Save Custom MVC forms data onto Sitecore Experience Forms Database

Today in this blog, we will be going through how we can leverage Sitecore Experience Forms database to save data from the custom MVC form.

Consider a scenario where we have custom MVC forms implemented on our website and we need to save the form data to Sitecore experience forms database such that content authors can use export functionality of sitecore forms to export the saved data or later create further customization such that the data can be used for experience analytics.

Also read: Sitecore 9.3 Custom Link Provider

In sitecore 9.3 by default, Experience forms data is saved in Experience Forms database.

Thus, we will be using Sitecore.ExperienceForms.Data and Sitecore.ExperienceForms.Data.Entities references that has functions that save data to sitecore forms table programmatically.

Also read: Personalization Buzzwords Explained

As per Figure 2, we will first need to create the sample form in Sitecore forms with the fields. (We will not be using this form for front end website but we need to create form and fields in Sitecore forms which exactly match our custom form fields as we need to MAP Sitecore form with custom form)

Also read: Sitecore Platform Inspection – How To Get Most Out Of It.

Now, lets consider that we have custom MVC form with two fields, Firstname and Email and we have controller action that we are using on Submit of custom MVC form. We need to save the form details onto Experience Forms database table. Below (Figure 3) is the sample controller that we will need to create. As per below sample, we will be creating the FormFieldDataModel (Figure 4) that will get the field id and field value pair for all the fields that we need to save and then we will need to call SaveDemoFormsData, that will store the data in forms database.

We will need to create a DemoSitecoreFormsRepository class (Figure 5) and implement methods that will store the data in forms tables. we will be using Sitecore.ExperienceForms.Data and Sitecore.ExperienceForms.Data.Entities references.

Thus, after following above steps the forms data will be saved in experience tables and can be accessed from Forms UI which can be used for export or any other further customizations.

Please feel free to contact us in case of any further details or feedback.

Stay Updated
Please enable JavaScript in your browser to complete this form.
LinkedIn
Share
Copy link
URL has been copied successfully!