How not to submit a form if validation is valid

How can I make sure that the form will not be submitted if one of the checks is false?

$('#form').submit(function(){
    validateForm1();
    validateForm(document.forms['dpart2']);
    validateForm(document.forms['dpart3']);                     
}); 
+5
source share
5 answers

If the function returns false, the form will not be submitted.

$('#form').submit(function(){
    return  validateForm1() 
            && validateForm(document.forms['dpart2']) 
            && validateForm(document.forms['dpart3']);                                         
              }
});
+6
source
$('#form').submit(function(){
    return (validateForm1() &&
            validateForm(document.forms['dpart2']) &&
            validateForm(document.forms['dpart3']))
});

Basically, you return false in the event handler function.

+7
source

, ... , , , , . , false, .

$("#myform").submit(function() {

    var ret = true;
    ret = validateForm1() && ret;
    ret = validateForm(document.forms['dpart2']) && ret
    ret = validateForm(document.forms['dpart3'])) && ret
    return ret;

});

, .

+4

validateForm (...) validateForm1() (true , ), :

$('#form').submit(function(){
    if (!validateForm1() || !validateForm(document.forms['dpart2']) || !validateForm(document.forms['dpart3'])) {
        return false;
    }
});
+3

The thought that arises automatically: even if you have implemented a thorough check on the client side, be prepared to receive any incorrect request data on the server that you can imagine.

Client-side validation never allows you to validate a server. This is just a usability bonus.

+3
source

All Articles