Fix #859 and also let's not trigger the submit handler if the form isn't valid.