Restructure code for checking form validity.
Fix user being able to submit form after cancelling file chooser in Chrome.