我一直在尝试向 WFFM 提交我自己的表格。我创建的表单与使用 WFFM 创建的表单相同,因此所有字段都正确映射。
我开始遵循以下步骤:https ://jermdavis.wordpress.com/2015/05/18/programmatic-wffm-submissions/
我必须对代码进行细微的更改才能SubmitActionManager
使其正常工作
Sitecore.Form.Core.Submit.SubmitActionManager 类的成员已移至 IActionExecutor 接口。要获取此接口的实例,请使用 (IActionExecutor)Factory.CreateObject ("wffm/wffmActionExecutor", false) 调用。
以下是我到目前为止的代码:
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
};
}
我不知道Sitecore.Form.Core.Analytics.AnalyticsTracker.SessionId
从哪里可以在里面使用它ExecuteSaving
,所以我使用了WffmActionEvent
。我遵循的指南也使用了Execute
,现在已弃用,所以我不得不选择ExecureSaving
(我最好的猜测)。
然而,这似乎并没有将提交的数据发布到数据库中。我无法在 WFFM 表单报告或 mongoDB 中看到我提交的任何内容。然而,日志表明表单正在保存到数据库中,不确定其他警告的含义。
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