Skip to content

Instantly share code, notes, and snippets.

@jammykam
Last active October 4, 2017 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jammykam/4fd62b2e27039ab70534bd514f00b73b to your computer and use it in GitHub Desktop.
Save jammykam/4fd62b2e27039ab70534bd514f00b73b to your computer and use it in GitHub Desktop.
Sitecore WFFM Checkbox With HTML field
using Sitecore.Form.Core.Attributes;
using Sitecore.Form.Core.Visual;
namespace MyProject.CMS.Custom.WFFM.Fields
{
public class CheckboxWithHtml : Sitecore.Form.Web.UI.Controls.Checkbox
{
private string _htmlText;
[VisualCategory("Appearance")]
[VisualProperty("Field Text (HTML):", 400)]
[VisualFieldType(typeof(TextAreaField))]
[Localize]
public string HtmlText
{
get {
return !string.IsNullOrEmpty(_htmlText) ? _htmlText : base.Title;
}
set
{
_htmlText = value;
}
}
}
}
using Sitecore.Forms.Mvc.ViewModels.Fields;
namespace MyProject.CMS.Custom.WFFM.Fields
{
public class CheckboxWithHtmlField : CheckboxField
{
public string HtmlText { get; set; }
public string Text
{
get
{
return !string.IsNullOrEmpty(HtmlText) ? HtmlText : base.Title;
}
set
{
HtmlText = value;
}
}
}
}
@using Sitecore.WFFM.Abstractions.Data.Enums
@using Sitecore.Forms.Mvc.Html
@model MyProject.CMS.Custom.WFFM.Fields.CheckboxWithHtmlField
@using (Html.BeginField())
{
var cssclass = Model.FormType == FormType.Inline ? "checkbox-inline" : "checkbox";
<div class="@cssclass">
<label>
@Html.CheckBoxFor(x => Model.Value)
@Html.BootstrapText("Text")
</label>
</div>
}

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/Checkbox with HTML Text
  • Template: /sitecore/templates/Web Forms for Marketers/Field Type
  • Assembly: MyProject.CMS.Custom
  • Class: MyProject.CMS.Custom.WFFM.Fields.CheckboxWithHtml
  • MVC Type: MyProject.CMS.Custom.WFFM.Fields.CheckboxWithHtmlField, MyProject.CMS.Custom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment