Modifying WFFM Information Using c#

拜拜、爱过 提交于 2019-12-11 12:09:17

问题


We have setup a simple form using Web Forms For Marketers on our Sitecore 6.4.0 site. The form is logging information just fine, and we have written a page to allow end-users to view the results, using the code from http://r-coding-sitecoreblog.blogspot.com/2011/11/extracting-data-from-sitecore-wffm.html mainly.

The next step in the progression is to allow a user to approve/reject a submission, and to either pass that form submission's information to a method, or to delete that form submission all together.

Is there a way to delete a form submission from the WFFM database using c#? I have tried the Sitecore.Forms.Data.DataManager.DeleteForms() method with no luck, and I suspect it deletes the entire form, not just the individual form submission.

EDIT: Additionally, I could handle even setting a flag on the individual form submission, marking it as approved/rejected, and just handling the show/hide logic in my code. So setting a value on a particular form submission would also work.


回答1:


You are always welcome to post questions related to the use of my code examples on my blog also :-)

You are on the right tracks with using the Datamanager class. Here's an example that deletes all records/submits for a form (one by one).

It will NOT delete the form it self. Only submitted database entries.

        string formID = ConfigurationManager.AppSettings["FormDataUploadID"].ToString(); 

        List<GridFilter> args = new List<Sitecore.Web.UI.Grids.GridFilter>();
        args.Add(new GridFilter("storageName", string.Empty, GridFilter.FilterOperator.Contains));
        args.Add(new GridFilter("dataKey", formID, GridFilter.FilterOperator.Contains));

        var submits = Sitecore.Forms.Data.DataManager.GetForms().GetPage(new PageCriteria(0, 0x7ffffffe), null, args);

        /// Create a Collection to Loop
        List<IForm> formlist = submits.ToList();

        /// Loop all forms from Database and delete each entry.
        foreach (IForm frm in formlist)
        {
            Sitecore.Forms.Data.DataManager.DeleteForms(new Sitecore.Data.ID(frm.FormItemId), frm.StorageName);
        }


来源:https://stackoverflow.com/questions/12518929/modifying-wffm-information-using-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!