Overriding the submit button turns out to be pretty simple -- create a custom BootstrapSubmit
method:
namespace Library.Models.ViewModels.Form
{
public static class WFFMHtmlHelperExtensions
{
public static MvcHtmlString CustomBootstrapSubmit(this HtmlHelper helper, string title = null)
{
TagBuilder tagBuilder1 = new TagBuilder("input");
tagBuilder1.Attributes.Add("type", "submit");
ISubmitSettings model1 = helper.ViewData.Model as ISubmitSettings;
string btnSize = string.Empty;
string btnType = string.Empty;
string btnText = string.Empty;
string btnPos = string.Empty;
if (model1 != null)
{
btnSize = model1.SubmitButtonSize;
btnType = model1.SubmitButtonType;
btnText = model1.SubmitButtonName;
btnPos = model1.SubmitButtonPosition;
}
tagBuilder1.Attributes.Add("value", btnText);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("btn").Append(" ").Append(btnSize).Append(" ").Append(btnType);
IStyleSettings model2 = helper.ViewData.Model as IStyleSettings;
if (model2 != null && model2.FormType != FormType.Inline)
{
TagBuilder tagBuilder2 = new TagBuilder("div");
tagBuilder2.AddCssClass(("form-submit-border " + btnPos).Trim());
tagBuilder1.AddCssClass(stringBuilder.ToString().Trim());
tagBuilder2.InnerHtml += tagBuilder1.ToString();
return MvcHtmlString.Create(tagBuilder2.ToString());
}
tagBuilder1.AddCssClass(stringBuilder.ToString().Trim());
return MvcHtmlString.Create(tagBuilder1.ToString());
}
}
}
-- add whatever modifications you want inside there- in my case, setting the button text from a page field:
var pageItem = Sitecore.Context.Item?.GlassCast<ICampaign_Gating_Page>();
if (pageItem != null && !String.IsNullOrEmpty(pageItem.Form_CTA_Override_Text))
{
btnText = pageItem.Form_CTA_Override_Text;
}
... and then in FormViewModel.cshtml (which should live under /Views/Form/EditorTemplates), replace @Html.BootstrapSubmit()
with @Html.CustomBootstrapSubmit()