umbraco / Umbraco.Forms.Issues

Public issue tracker for Umbraco Forms
29 stars 0 forks source link

Multiple form submissions with forms 13.0.1 and aspnet-validation #1182

Closed james-whittington1 closed 6 months ago

james-whittington1 commented 7 months ago

A brief description of the issue goes here.

When using the aspnet-validation framework the form can be submitted multiple times.

I was sure that I remembered this being solved a long time ago, so I checked the js scripts and can see that the disabled state is only set when using jquery validation :(

Reproduction

Create a new project and set up and render a form to the front end.

Click the submit button several times. the form should keep resubmitting (i actually got some kind of server error relating to database scopes).

Confirm that the form was submitted more than once in the back office.

this can be fixed by including something like this in the aspnet-validation setup. Perhaps there is a way to have a shared routine to do handle this?

var submitInputs = document.querySelectorAll(".umbraco-forms-form input[type=submit]:not(.cancel)"); for (let i = 0; i < submitInputs.length; i++) { var input = submitInputs[i] as HTMLInputElement;

 const clickHandler = (e: Event) => {
     e.preventDefault();
     const form = input.closest('form') as HTMLFormElement;

     validationService.validateForm(form, (valid) => {
         if (valid) { 
             form.submit();
             input.setAttribute("disabled", "disabled");  
         }
     }); 
 }

 input.addEventListener("click", clickHandler);
AndyButland commented 6 months ago

Thanks for reporting this @james-whittington1, and of course for providing the code snippet to help resolve. To be honest I hadn't realised we had this in place for the jquery validation, but given we do, we should certainly have it for the other validation framework supported. You'll find this in 13.1, due out next week.