0

I want to add a functionality in which Sitecore user can add some token into a in WFFM Introduction rich text field as an example and the custom code will check and replace this token with the matching value.

I added a processor to the pipeline but this will be called for all fields except WFFM fields.

My site is Sitecore 8.1 update 1, Any suggestion how I can make this processor triggered for the WFFM fields, Is there another pipeline that I should use?

Last thing, This is working just fine in Sitecore 7.5 but after upgrade to Sitecore 8.1 it doesn't work anymore.

1

The Introduction field of the WFFM form is rendered using a UI control. I think the easiest way to achieve your token replacement solution is to modify this UI control overriding its OnLoad() method to add your token replacement logic.

The main Form control is defined in the SitecoreSimpleFormAscx.ascx control (\sitecore modules\Web\Web Forms for Marketers\Control\SitecoreSimpleFormAscx.ascx) and here you'll find the Form Introduction control that is responsible to render the form introduction (<wfm:FormIntroduction ID="intro" runat="server"/>).

Create a CustomFormIntroduction control following the implementation of the original FormIntroduction control (see code below), add your logic to replace the tokens in the OnLoad method, and then replace the existing default FormIntroduction control with your custom control (<customwfm:CustomFormIntroduction ID="intro" runat="server"/>).

CustomFormIntroduction class code:

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Sitecore.Data.Items;
using Sitecore.Form.Web.UI.Controls;
using Sitecore.Xml.Xsl;

namespace Custom.WFFM.Controls
{
    [ToolboxData("<div runat=\"server\"></div>")]
    public class CustomFormIntroduction : FormText
    {
        public CustomFormIntroduction()
          : base((Item)null, Sitecore.Form.Core.Configuration.FieldIDs.FormIntroductionID, HtmlTextWriterTag.Div)
        {
        }

        public CustomFormIntroduction(Item item)
          : base(item, Sitecore.Form.Core.Configuration.FieldIDs.FormIntroductionID, HtmlTextWriterTag.Div)
        {
        }

        protected override void OnLoad(EventArgs e)
        {
            this.Attributes["class"] = "scfIntroBorder";
            if (!(this.Item.Fields[Sitecore.Form.Core.Configuration.FieldIDs.ShowFormIntroID].Value == "1"))
                return;
            if (this.Item == null)
                return;
            Sitecore.Web.UI.WebControls.FieldRenderer fieldRenderer = new Sitecore.Web.UI.WebControls.FieldRenderer();
            fieldRenderer.Item = this.Item;
            fieldRenderer.FieldName = this.Item.Fields[this.Field].Name;
            fieldRenderer.Parameters = this.Parameters ?? string.Empty;
            fieldRenderer.DisableWebEditing = this.DisableWebEditing;
            RenderFieldResult renderFieldResult = fieldRenderer.RenderField();
            this.Controls.Add((Control)new Literal()
            {
                Text = renderFieldResult.ToString() // HERE ADD YOUR LOGIC TO REPLACE THE TOKEN
            });
        }
    }
}
  • This is how I can handle one field, Is there a way I can add a processor in the rendering of WFFM field, Is there a specific pipeline,? – Mohammed Syam Feb 19 '17 at 12:00
1

The easiest would probably be, to inherit the WFFM field and add some of your own custom logic to it. WFFM field types are defined here:

enter image description here

Find the field you need to override, and then point the configuration to your custom code.

enter image description here

You did not specify whether you're using Webforms or MVC. But they're both more or less the same - you just need to make sure your code is inheriting from the correct base class.

Image Sources and a full write-up of this, here: Creating a Custom Field Type in WFFM for Sitecore

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.