'Stop a form after it has submitted

Just like the question asks, is there a way to stop a form after it has been submitted?

This is not a 'how do I validate' question. I cannot call a function and return true/false after some conditional. The condition on which to stop the form depends on file size, and that can only be accessed after the file has begun to be uploaded (via my form submission).

No, form submissions for file handling is not optimal, but I'm working with legacy code.



Solution 1:[1]

If by "After it has submitted", you mean "after the user has clicked on the button", a simple return false; or e.stopPropagation() is more than fit for duty.

If, however, by "After it has submitted", you mean "After the onsubmit event", on the client side, you are SOL. Your best bet is to do the form submission in two steps if you are dealing with legacy browsers: the file upload first, and check for returns on this... and if it worked, chain the other POST request using AJAX.

It's messy, but it's your only bet. :-(

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sébastien Renauld