Skip to content

Instantly share code, notes, and snippets.

@PetersonDave
Created October 2, 2013 20:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PetersonDave/6800139 to your computer and use it in GitHub Desktop.
Save PetersonDave/6800139 to your computer and use it in GitHub Desktop.
Prevent users from submitting forms twice in Sitecore's Web Forms for Marketers.
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) {{ $(submitButton).disabled = Page_ClientValidate(groupValidator);}}";
protected override void OnLoad(EventArgs e)
{
base.OnLoad(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);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment