I have a form with jQuery validation and I've created functions to return true or false if all fields are correctly filled. My problem is how and which function do I use to prevent a form from submitting, if my function returns false.
Thank you all in advance.
--- Edit ---
This is the function (a basic one) that I've made to check if all fields were filled correctly:
$("#btn_create").click(function(){
$("input").each(function(){
if($(this).css("border-color") == "rgb(249, 57, 57)"){
check = false;
return false;
} else {
check = true;
}
});
if(check == false){
$("#fill").fadeIn("slow");
} else {
$("#fill").fadeOut("slow");
}
});
<form method="post" class="create">
<div class="form-group col-lg-12">
<input type="text" class="form-control" id="name" placeholder="Name">
</div>
<div class="form-group col-lg-12">
<input type="email" class="form-control" id="email" placeholder="E-mail">
</div>
<div class="form-row">
<div class="form-group col-lg-6">
<input type="password" class="form-control" id="pass" placeholder="Password">
</div>
<div class="form-group col-lg-6">
<input type="password" class="form-control" id="repass" placeholder="Retype Password">
</div>
</div>
<div class="form-group col-lg-12">
<input type="text" class="form-control" id="tlm" minlength="9" maxlength="9" placeholder="Contact">
</div>
<div class="form-group col-lg-12">
<label class="label label-danger" id="fill">Please, fill all fields correctly!</label>
</div>
<div class="form-group col-lg-12 text-right">
<button type="submit" id="btn_create" class="btn btn-primary">Sign in</button>
</div>
</form>
When the fields are not filled correctly the border-color is red so I ended up doing some validation with that, if there are some input with border-color red, check = false.
PS.: Before asking this questions I've search for answers such as prevent default... Please do not say its duplicated because I've tried that one and for some reason didn't work.