# How to prevent forms from being submitted twice

**URL:** <https://discuss.workflowgen.com/t/how-to-prevent-forms-from-being-submitted-twice/295>\
**Category:** Form Designer\
**Created:** [January 21, 2016, 10:56am UTC](https://discuss.workflowgen.com/t/how-to-prevent-forms-from-being-submitted-twice/295 "2016-01-21T10:56:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wfg-admin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discuss.workflowgen.com/wfg-admin/32/714_2.png) [@wfg-admin](https://discuss.workflowgen.com/u/wfg-admin)\
**Post date:** [January 21, 2016, 10:56am UTC](https://discuss.workflowgen.com/t/how-to-prevent-forms-from-being-submitted-twice/295/1 "2016-01-21T10:56:59Z")

</div>

To prevent forms from being submitted twice, such as when a user double-clicks on the Submit button, add the following JavaScript code, including the opening and closing tags, on the **Web References** tab in the **Form configuration** panel. This is supported in Internet Explorer 9 and later, Edge, Chrome, and Firefox.

```auto
// if $selectedObject is undefined, we are not in the form designer
    if (typeof $selectedObject === "undefined")
    {
        var windowFirstLoad=true;
    
        // Standard page Load
        window.onload = function ()
        {
            preventDblSubmit();
        }
        // Ajax page load
        function pageLoad()
        {
            if (!windowFirstLoad)
            {
                preventDblSubmit();
            }
            else
            {
                windowFirstLoad=false;
            }
        }
   
        function preventDblSubmit()
        {    
            var sourceIsButton = false;
            var submitButton = document.getElementById('submitButton');
            var draftButton = document.getElementById('saveAsDraftButton');
    
            if(submitButton)
            {
                submitButton.addEventListener("click", function(){
                    sourceIsButton = true;
                });
            }
            
            if(draftButton)
            {
                draftButton.addEventListener("click", function(){
                    sourceIsButton = true;
                });
            }
          
            form1.addEventListener("submit", function()
            {                 
                if(!sourceIsButton)
                {
                    return true;
                }
                
                // If the page contains .NET validators, check the Page_IsValid variable
                if(typeof Page_IsValid !== 'undefined')
                {                    
                   if (!Page_IsValid)
                   {
                       return false;   
                   }
                }
                                
                // Prevent further clicks
                if(submitButton)
                {
                    submitButton.onclick=function(){ return false; };
                    submitButton.ondblclick=function(){ return false; };    
                }
                
                if(draftButton)
                {
                    draftButton.onclick=function(){ return false; };
                    draftButton.ondblclick=function(){ return false; };    
                }
                return true;    
            });
        }
    }

```
