We just had the exact same requirements come up and I solved this using a custom field.
Create a new field, CheckboxWithHtml
which inherits from the default checkbox and adds a new 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;
}
}
}
}
Note in the above, I didn't override any render methods. If you want to utilise this for ASP.Net WebForms then you will need to override and provide implementation of these methods to use the new property.
Next create a model which will be used by MVC.
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;
}
}
}
}
The implementation of this property is the same as before and if HtmlText
is not set, it will fall back to using the default Title property.
And finally the view for this field, /Views/Form/EditorTemplates/CheckboxWithHtmlField.cshtml:
@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>
}
You need to register the 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/Simple Types/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
The field should now be available to select and an additional input box present to allow you to enter your HTML.
The above code is valid for Sitecore 8.1 Update-3. You may need to make some tweaks for Sitecore 8.2.