Modifying WFFM Information Using c#

2019-08-13 17:40发布

问题:

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);
        }