And now for a quick hint, how do we access contacts from a WFFM form programmatically? This task might sound straight forward; however, the information I found online was pretty confusing, from SQL queries to custom save actions.
Of course, we could add an action to our form that would add contacts to a contact list and retrieve these contacts from that list. However, what if we can’t edit the form or we need to access contacts that have already completed the form.
This was the case when we needed to create a schedule task that would export all contacts that completed a form on a given interval. Fortunately, there’s one simple method that takes our WFFM Sitecore item, and retrieves all contact entries that have completed our form: DependenciesManager.DataProvider.GetFormData()
In order to use this method, we need to add a couple of references to our project:
And with these, we are ready to start working with our WFFM entries:
FormItem item = Sitecore.Forms.Core.Data.FormItem.GetForm(formID); IEnumerable<FormData> entries = DependenciesManager.DataProvider.GetFormData(item.ID.Guid);
And that’s it! With this, we can access our fields for each contact. Hope this quick tip is helpful. Please make sure to leave any comments or questions below 🙂