I have been trying to submit a my own form to WFFM. The form i created is identical to the one created with WFFM, that way all fields map correctly.
I began following the following steps: https://jermdavis.wordpress.com/2015/05/18/programmatic-wffm-submissions/
I had to make minor changes to the code in order to get the SubmitActionManager to work
The members of Sitecore.Form.Core.Submit.SubmitActionManager class have been moved to the IActionExecutor interface.To obtain the instance of this interface use the (IActionExecutor)Factory.CreateObject ("wffm/wffmActionExecutor", false) call.
Below is the code I have so far.
public void SubmitData(ContactUsFormModel data)
{
var results = new List<ControlResult>();
results.Add(makeControlResult(Models.Constants._cufFirstNameID, "First Name", data.FirstName));
results.Add(makeControlResult(Models.Constants._cufLastNameID, "Last Name", data.LastName));
results.Add(makeControlResult(Models.Constants._cufEmailID, "Email", data.Email));
results.Add(makeControlResult(Models.Constants._cufCompanyID, "Company", data.Company));
results.Add(makeControlResult(Models.Constants._cufSubjectID, "Subject", data.Subject));
results.Add(makeControlResult(Models.Constants._cufMessageID, "Message", data.Message));
var formItem = Sitecore.Context.Database.GetItem(Models.Constants._contactUsFormID);
var simpleForm = new SitecoreSimpleForm(formItem);
var saveActionXml = simpleForm.FormItem.SaveActions;
var actionList = Sitecore.Form.Core.ContentEditor.Data.ListDefinition.Parse(saveActionXml);
var actionDefinitions = new List<ActionDefinition>();
actionDefinitions.AddRange(actionList.Groups.SelectMany(x => x.ListItems).Select(li => new ActionDefinition(li.ItemID, li.Parameters) { UniqueKey = li.Unicid }));
var SubmitActionManager = (IActionExecutor)Factory.CreateObject("wffm/wffmActionExecutor", false);
Sitecore.Form.Core.WffmActionEvent sessionID = new Sitecore.Form.Core.WffmActionEvent();// SessionIDGuid
var result = SubmitActionManager.ExecuteSaving(ID.Parse(Models.Constants._contactUsFormID), results.ToArray(), actionDefinitions.ToArray(), true, ID.Parse( sessionID.SessionIDGuid ));
}
private ControlResult makeControlResult(string fieldID, string fieldName, string fieldValue)
{
return new ControlResult(fieldName, fieldValue, string.Empty)
{
FieldID = fieldID,
FieldName = fieldName,
Value = fieldValue,
Parameters = string.Empty
};
}
I wasnt sure where to get Sitecore.Form.Core.Analytics.AnalyticsTracker.SessionId from to use inside ExecuteSaving, so I used WffmActionEvent.
Also the guide I followed uses Execute, which is now deprecated, so I had to go with ExecureSaving (my best guess).
This however doesn't seem to be posting the submitted data into the databse. I am unable to see any of my submissions inside WFFM Form Reports or inside mongoDB.
The logs however state that the form is being saved to the database, not sure what the other warnings mean.
24688 17:20:39 WARN [WFFM] Tracker.Current is not initialized
24688 17:20:39 INFO AUDIT (sitecore\admin): [WFFM] Form {978DBF4C-0F56-45A8-A9AC-52EF8D995DDF} is saving to db
24688 17:20:39 WARN [WFFM] Tracker.Current.Contact is not initialized
24688 17:20:39 WARN [WFFM] Tracker.Current.Interaction is not initialized
24688 17:20:39 WARN [WFFM] CurrentSession is not initialized