Our site has a form that is injected into a jQuery dialog. Upon entering form data and clicking the submit button (a jQueryUI dialog button), the form is first validated by javascript then submitted to the server. I have found that after pasting in a value to the one textbox that is mandatory and submitting, occasionally when I open the form the next time, it attempts to submit immediately without the user clicking the button (I verified this with debugger statements just before every instance of .submit() which were hit only when form submission happened with a button click).
Has anyone else encountered an instance of unintended form submission, and other than server side validation was there any way you could combat it?
Just to be clear, the order of events are as follows:
- User clicks the Add button which gets the form (partial view) and injects it into the dialog, then opens the dialog.
- User pastes a value into the mandatory textbox (there are several other controls).
- User clicks the Submit button which performs low level validation and submits the form via ajax, closing the dialog after success.
- Rinse and repeat until:
- User clicks the Add button which gets the form and injects it into the dialog, which opens and them immediately submits, failing validation on the server.
Form.submit callback
$("#SearchEdit>form").submit(function (e) {
if (TermPresent()) {
return true;
} else {
e.preventDefault();
return;
}
});
function TermPresent() {
return ($("textarea#MySearch_SearchTerms").val() != "" ? true : false);
}
You could change
type="submit"totype="button", then summit from the bottom of your validation code instead of allowing the form to submit itself.