Preventing a form from submitting when validation returns false is possible.
Here's an example:
<form name="registration" action="registration.php" onsubmit="return validate()">
<!-- some inputs like: -->
<input type="text" id="username" name="username">
<input type="text" id="firstname" name="firstname">
<input type="text" id="lastname" name="lastname">
<!-- and some others... -->
</form>
The javascript function 'validate()' contains various checks as follows:
function validate() {
checkUsername();
checkPassword();
checkFirstname();
checkLastname();
checkBirthdate();
checkEmail();
checkPhone();
}
If one of the validations fails, you want the form not to submit. One approach can be to modify the 'validate()' function:
function validate() {
var truth1 = checkUsername();
var truth2 = checkPassword();
var truth3 = checkFirstname();
var truth4 = checkLastname();
var truth5 = checkBirthdate();
var truth6 = checkEmail();
var truth7 = checkPhone();
return (truth1 && truth2 & truth3 & truth4 & truth5 & truth6 & truth7);
}
If your form still submits despite returning false, consider checking for any syntax errors in your code.
Another solution could involve changing how your checks are evaluated within the 'validate()' function.