sitecore8 - Sitecore WFFM: Issues Submitting form programmaticaly -
i have been trying submit own form wffm. form created identical 1 created wffm, way fields map correctly.
i began following following steps: https://jermdavis.wordpress.com/2015/05/18/programmatic-wffm-submissions/
i had make minor changes code in order submitactionmanager work
the members of sitecore.form.core.submit.submitactionmanager class have been moved iactionexecutor interface.to obtain instance of interface use (iactionexecutor)factory.createobject ("wffm/wffmactionexecutor", false) call.
below code have 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 sitecore.form.core.analytics.analyticstracker.sessionid use inside executesaving, used wffmactionevent. guide followed uses execute, deprecated, had go execuresaving (my best guess).
this doesn't seem posting submitted data databse. unable see of submissions inside wffm form reports or inside mongodb. logs state form being saved database, not sure other warnings mean.
24688 17:20:39 warn [wffm] tracker.current not initialized 24688 17:20:39 info audit (sitecore\admin): [wffm] form {978dbf4c-0f56-45a8-a9ac-52ef8d995ddf} saving db 24688 17:20:39 warn [wffm] tracker.current.contact not initialized 24688 17:20:39 warn [wffm] tracker.current.interaction not initialized 24688 17:20:39 warn [wffm] currentsession not initialized
as using sitecore 8 form submission stored in mongodb. sitecore's implementation of mongodb, xdb relies on tracking users, calling them contacts.
most data stored in xdb linked contact via contactid. error messages finding in log stating tracking not enabled, therefore no contact present , there no interaction between site , user.
therefore need start sitecore.tracker recommend using following code
if (!tracker.isactive) tracker.starttracking(); if (!tracker.isactive || tracker.current.contact == null) { // handle no tracker , contact } now have tracking working need use correct id sessionid variable.
the blog following based on sitecore 7, in sitecore 8 sitecore.form.core.analytics.analyticstracker.sessionid removed. decompiled sitecore 7 code , sitecore.form.core.analytics.analyticstracker.sessionid uses tracker.currentvisit.visitid.
however namespace has changed in sitecore 8, visits called interactions instead of variable sessionid want use
tracker.current.interaction.interactionid; that should resolve issue having may need bit more development finish off.
Comments
Post a Comment