Created
October 2, 2013 20:36
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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