David Peterson bio photo

David Peterson

David is a Sitecore Architect with ATP World Tour, founder of the Philadelphia Sitecore Users Group and Technical Sitecore MVP. Often reminiscing of his days as a Sysop and being Elite.

Email Twitter LinkedIn Github

When building forms using Web Forms for Marketers (WFFM), custom save actions can be added to save form data to a database or email a confirmation message. This post details an approach to disable the submit button to prevent multiple save actions from being triggered, such as sending multiple confirmation emails.

Similar to the approach outlined here for attaching an alert on the submit button, we’re going to extend the class responsible for rendering WFFM forms and attach javascript to the submit button.

using System;
using Sitecore.Form.Core.Renderings;
using Sitecore.Form.Web.UI.Controls;

namespace Custom.Form.Web.UI.Controls
    public class PreventDoubleClickFormRender : FormRender
        // disables submit button if group validator for submit is valid
        private const string PreventDoubleSubmitJs = @"function disableSubmitButton(groupValidator, submitButton) ";

        protected override void OnLoad(EventArgs e)

            Page.ClientScript.RegisterClientScriptBlock(GetType(), ID, PreventDoubleSubmitJs);

            var formSubmitId = FormInstance.ID + SitecoreSimpleForm.prefixSubmitID;
            var submit = FormInstance.FindControl(formSubmitId) as SubmitButton;
            if (submit != null)
                submit.Attributes["onclick"] += string.Format("disableSubmitButton('{0}', '{1}');", submit.ValidationGroup, submit.ClientID);

Validating Input

An important note about this code is that we do not disable the button if the form fails validation. On submit, ASP.NET’s Page_ClientValidate is called to evaluate all validators defined within the group validator for the submit button submit.ValidationGroup.

A Few Notes on Implementing

  • Notice the naming convention for the submit control. Sitecore.Form.Web.UI.Controls.SitecoreSimpleForm defines the naming convention within the control’s OnInit() method.
  • When appending the script to the onclick attribute of the submit button, do not use OnClientClick() as the submit control will replace your code within OnLoad() (reference: Sitecore.Form.Web.UI.Controls.FormSubmit).

Wiring Up The Rendering

The last step in using our new code is to reference the class within the defined Form rendering. Updating the namespace, tag and assembly bring it all together:

wffm settings