Sunday 17 September 2017

WFFM : Customizing SQL form data provider

1 comment


I’ve got a task where I have to save user’s browser information (Browser name and version) into Sitecore WFFM SQL database as part of the every WFFM form submission. Website support team would like to know the user’s browser that is being used for accessing the production site, so that they don't have to request this information while troubleshooting any issues the user has reported via the Feedback/Troubleshooting Contact Us form.

Environment Details

Sitecore 8.2 update 5 (CMS only mode), Web Forms for Marketers 8.2 rev. 170807


I’ve decided to customize WFFM save to database functionality and add new FieldData to form field list dynamically while saving form data. This new FieldData will consist user’s browser information (Browser name and version). This implementation can be achieved by below three ways:
  1. Customizing SQL form data provider
  2. Create new save to database action
  3. Create a custom field. 
We have to also modify export form data to excel functionality so that form reports include user’s browser information. In this blog post, I’ll explain how to create custom SQL provider to store form data into SQL database.

WFFM Configuration

In the \Website\Data folder of your Sitecore instance, attach the Sitecore_Wffm.mdf database to the SQL Server, and add a connection string with the name “wffm” in the ConnectionStrings.config file, located in the \Website\App_Config folder.
<add name="wffm" connectionString="Data Source=(local);Initial Catalog=instance_name_wffmDB;Integrated Security=False;User ID=sa;Password=12345"

Customizing SQL form data provider

  1. Create a new CustomSqlFormsDataProvider class and inherit SqlFormsDataProvider class.
  2. Write custom logic to add new FieldData to form field list dynamically while saving form data.

  3. Add a config patch as below to configure CustomSqlFormsDataProvider.
    <configuration xmlns:patch="" xmlns:set="">
            <formsDataProvider patch:instead="*[@ref='/sitecore/wffm/analytics/analyticsFormsDataProvider']" ref="/sitecore/wffm/analytics/customSqlFormsDataProvider"/>
            <customSqlFormsDataProvider type="Website.WFFM.Providers.CustomSqlFormsDataProvider, Website">
              <param name="connectionStringName">wffm</param>
              <param name="settings" ref="/sitecore/wffm/settings"/>
              <param name="connectionProvider" ref="/sitecore/wffm/analytics/connectionProvider"/>
  4. Select the relevant WFFM form and in the Submit section, select Save Form Data To Storage checkbox.
  5. Publish Sitecore related changes. Build the code and deploy assembly in bin folder of your Sitecore instance.
In next blog post, I’ll explain how to create a custom save to database action. Comments and suggestions are most welcome. Happy coding!


After publishing this blog post, I had a nice fruitful conversation with Sitecore MVP Kamruz Jaman regarding this implementation. If you are not already using custom SQL provider in your solution then prefer to create a custom field to handle above scenario. Nevertheless, this WFFM blog post series will give you fair idea about how to customize SQL form data provider and export form data to excel functionality.

1 comment :