Web Forms for Marketers - Submit form data programmatically

落爺英雄遲暮 提交于 2019-12-09 23:41:37

问题


I'm currently scoping whether or not to include Web Forms for Marketers on a project I'm currently working on. The web site will be a responsive design with a rich UI and so I would like to have full control over the rendering of the form, e.g. labels, input fields etc and would rather not have to modify the WFFM SitecoreSimpleFormAscx.ascx file or the associated css file.

Is there currently any way, using C# code, to submit some form data to a Web Forms for Marketers form that is already created in Sitecore (assuming I have knowledge of all the fields)? The WFFM reference guide has a code snippet for accessing already submitted web form data but nothing for just submitting some.


回答1:


If you don't want to dig into custom controls for the forms you might try performing a POST to a page that contains the WFFM form via JavaScript from your responsive page. Alternatively you could embed and hide the wffm form on your page and stunt drive it with script again. I think the second approach would be better as it would allow you to more directly respond to validation failures.




回答2:


You could submit form code to the WFFM DB using the following code, and it would show up seamlessly in the report page of that form:

Say you have your list of fields populated in a list of this class:

public class WffmField
    {
        public string FieldName { get; set; }
        public string FieldGuid { get; set; }
        public string FieldValue { get; set; }
    }

the field guid would be the guid from sitecore:

You can then save to the WFFM database:

// This should be populated with the data you want to send to the WFFM database
var fields = new List<WffmField>(); 
var wffmDatabaseFields = fields.Select(GetWFFMDatabaseField).ToList();

Sitecore.Forms.Data.DataManager.InsertForm(
    formId: new Sitecore.Data.ID("<Form guid here>"),
    fields: new AdaptedResultList(wffmDatabaseFields),
    sessionID: AnalyticsTracker.SessionId,
    data: null);

Hope this helps!



来源:https://stackoverflow.com/questions/16578237/web-forms-for-marketers-submit-form-data-programmatically

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