Created
September 16, 2017 17:20
-
-
Save Dheer-Rajpoot/e7d74ad715a5cb3af58e4e856037916c to your computer and use it in GitHub Desktop.
WFFM : custom SQL provider to store form data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Sitecore.Diagnostics; | |
using Sitecore.WFFM.Abstractions.Analytics; | |
using Sitecore.WFFM.Abstractions.Shared; | |
using Sitecore.WFFM.Analytics.Providers; | |
using System; | |
using System.Collections.Generic; | |
using System.Web; | |
namespace Website.WFFM.Providers | |
{ | |
public class CustomSqlFormsDataProvider : SqlFormsDataProvider | |
{ | |
public CustomSqlFormsDataProvider(string connectionStringName, ISettings settings, IDbConnectionProvider connectionProvider) : base(connectionStringName, settings, connectionProvider) | |
{ | |
} | |
public override void InsertFormData(FormData form) | |
{ | |
try | |
{ | |
Assert.ArgumentNotNull(form, "form"); | |
Assert.ArgumentNotNull(form.Fields, "form.Fields"); | |
//custom logic starts here | |
InsertBrowserDetails(ref form); | |
//custom logic ends here | |
base.InsertFormData(form); | |
Log.Audit("Form data is successfully saved to db ", this); | |
} | |
catch (Exception e) | |
{ | |
Log.Error("Exception occured while saving Form data " + e.Message, this); | |
} | |
} | |
/// <summary> | |
/// Insert Browser Name and Version | |
/// </summary> | |
/// <param name="fields"></param> | |
public void InsertBrowserDetails(ref FormData form) | |
{ | |
List<FieldData> fieldDataList = new List<FieldData>(form.Fields); | |
var request = HttpContext.Current.Request; | |
FieldData browserFieldData = new FieldData() | |
{ | |
Id = Guid.NewGuid(), | |
FieldId = new Guid("{2908AEEB-8663-4127-9BFD-FD7E6FCE2602}"), | |
FieldName = "BROWSER DETAILS", | |
Value = "Browser Name : " + request.Browser.Browser + " Browser Version : " + request.Browser.Version, | |
Data = null | |
}; | |
fieldDataList.Add(browserFieldData); | |
form.Fields = fieldDataList; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment