Saving data to the Sitecore WFFM database programmatically

I am sure I am not the first to think that the Sitecore WFFM forms are not really as robust as we might like.
But because of the ready made form reports and marketing advantages, we might still want to leverage the wffm backend database for storing the form information, with an independent form front end.

This post is to show how we can save the form information to the wffm database without using the actions provided on submit.
Say you have your list of fields populated in a list of this class:

    public class WffmField
            public string FieldName { get; set; }
            public string FieldGuid { get; set; }
            public string FieldValue { get; set; }

The field guid would be the guid from sitecore:

You can then save to the WFFM database:

    // This should be populated with the data you want to send to the WFFM database
    var fields = new List<WffmField>(); 
    var wffmDatabaseFields = fields.Select(GetWFFMDatabaseField).ToList();
    	formId: new Sitecore.Data.ID("<Form guid here>"),
    	fields: new AdaptedResultList(wffmDatabaseFields),
    	sessionID: AnalyticsTracker.SessionId,
    	data: null);

This data will be available in the form reports now as expected.


Please note, you will need to add a reference to Sitecore.Forms.Core dll and following are the included namespaces:

using Sitecore.Form.Core.Analytics;
using Sitecore.Form.Core.Client.Data.Submit;
using Sitecore.Form.Core.Controls.Data;

2 thoughts on “Saving data to the Sitecore WFFM database programmatically

  1. You are also able to take this a step further by creating a custom Sitecore.Forms.Data.DataProviders.WFMDataProviderBase — this lives in Sitecore.Forms.Core.dll — to manipulate values before insertion and/or during retrieval from WFFM:

    I also showcased another example of how to do this during my Sitecore User Group presentation in London, UK in 2013:



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s