Skip to content

Instantly share code, notes, and snippets.

@jammykam
Last active October 4, 2017 18:16
Show Gist options
  • Save jammykam/5d58655d6749d59a7dbaf19ae12420b1 to your computer and use it in GitHub Desktop.
Save jammykam/5d58655d6749d59a7dbaf19ae12420b1 to your computer and use it in GitHub Desktop.

Create WFFM field in Sitecore under /sitecore/system/Modules/Web Forms for Marketers/Settings/Field Types. For example:

  • Item Path: /sitecore/system/Modules/Web Forms for Marketers/Settings/Field Types/Custom/Label
  • Template: /sitecore/templates/Web Forms for Marketers/Field Type
  • Assembly: MyProject.CMS.Custom
  • Class: MyProject.CMS.Custom.WFFM.Fields.Label
  • MVC Type: MyProject.CMS.Custom.WFFM.Fields.LabelField, MyProject.CMS.Custom
using System;
using System.ComponentModel;
using Sitecore.Form.Core.Attributes;
using Sitecore.Form.Core.Visual;
using Sitecore.WFFM.Abstractions.Actions;
namespace MyProject.CMS.Custom.WFFM.Fields
{
public class Label : Sitecore.Form.Web.UI.Controls.CssClassControl
{
private string _htmlText;
private string _value = String.Empty;
[VisualCategory("Appearance")]
[VisualProperty("Field Text (HTML):", 100)]
[VisualFieldType(typeof(TextAreaField))]
[Localize]
public string HtmlText
{
get
{
return !string.IsNullOrEmpty(_htmlText) ? _htmlText : this.Title;
}
set
{
_htmlText = value;
}
}
[Description("Title")]
[Bindable(true)]
public string Title { get; set; }
public override ControlResult Result
{
get
{
return new ControlResult(this.ControlName, (object)String.Empty, (string)null);
}
set { _value = String.Empty; }
}
}
}
using System;
using System.ComponentModel;
using Sitecore.Forms.Mvc.Interfaces;
using Sitecore.Forms.Mvc.ViewModels;
using Sitecore.WFFM.Abstractions.Actions;
namespace MyProject.CMS.Custom.WFFM.Fields
{
public class LabelField : FieldViewModel, IFieldResult, IContainerMetadata
{
public string HtmlText { get; set; }
public string Text
{
get
{
return !string.IsNullOrEmpty(HtmlText) ? HtmlText : base.Title;
}
set
{
HtmlText = value;
}
}
[DefaultValue("")]
public virtual string Value { get; set; }
public string ResultParameters { get; set; }
public virtual ControlResult GetResult()
{
return new ControlResult(this.FieldItemId, this.Name, (object)String.Empty, this.ResultParameters, false);
}
}
}
@using Sitecore.Forms.Mvc.Html
@model MyProject.CMS.Custom.WFFM.Fields.LabelField
@using (Html.BeginField())
{
@Html.BootstrapText("Text")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment