I am trying to make jquery validation on a form, everything works about checking the inputs, but when everything is right, it doesnt "go further" and return anything.
function validateFields() {
var fname = $("input#fname").val();
if (fname == "") {
$( "#WrapSu" ).css({"border-radius":"0px 0px 3px 3px"});
$( "#Fejl" ).html("<p class=\"c\">First name missing!</p>");
$( "#Fejl" ).slideDown( "slow" );
return false;
}
var lname = $("input#lname").val();
if (lname == "") {
$( "#WrapSu" ).css({"border-radius":"0px 0px 3px 3px"});
$( "#Fejl" ).html("<p class=\"c\">Last name missing!</p>");
$( "#Fejl" ).slideDown( "slow" );
return false;
}
var femail = $("input#femail").val();
if (femail == "") {
$( "#WrapSu" ).css({"border-radius":"0px 0px 3px 3px"});
$( "#Fejl" ).html("<p class=\"c\">Email missing!</p>");
$( "#Fejl" ).slideDown( "slow" );
return false;
}
var lemail = $("input#lemail").val();
if (lemail == "") {
$( "#WrapSu" ).css({"border-radius":"0px 0px 3px 3px"});
$( "#Fejl" ).html("<p class=\"c\">Email missing!</p>");
$( "#Fejl" ).slideDown( "slow" );
return false;
}
var cemail = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
if (femail !== "") {
$( "#WrapSu" ).css({"border-radius":"0px 0px 3px 3px"});
if(!cemail.test(femail)){
$( "#Fejl" ).html("<p class=\"c\">Your email is invalid.</p>");
$( "#Fejl" ).slideDown( "slow" );
return false;
}
}
var fpassword = $("input#fpassword").val();
if (fpassword == "") {
$( "#WrapSu" ).css({"border-radius":"0px 0px 3px 3px"});
$( "#Fejl" ).html("<p class=\"c\">Password missing!</p>");
$( "#Fejl" ).slideDown( "slow" );
return false;
}
var lpassword = $("input#lpassword").val();
if (lpassword == "") {
$( "#WrapSu" ).css({"border-radius":"0px 0px 3px 3px"});
$( "#Fejl" ).html("<p class=\"c\">Confirm password!</p>");
$( "#Fejl" ).slideDown( "slow" );
return false;
}
var datastring = 'fname='+ fname +'&lname='+ lname +'&email='+ femail +'&password='+ fpassword;
$.ajax({
type: "POST",
url: "opret.php",
data: dataString,
success: function() {
if(responseText == 1) {
$( "#Fejl" ).html("<p class=\"c\">virker</p>");
} else { // else blank response
$( "#Fejl" ).html("<p class=\"c\">virker2</p>");
}
}
});
return false;
};
$('form#opret').on('submit',function(e) {
e.preventDefault();
var success=validateFields();
});
And i do not know what needs to be changed, i have tried much, and my experience stops, i have no idea what it is..
i would love for anyone to kindly explain me whats the error, so that i will learn it :-) php code:
1<?php
include("config.php");
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$email=$_POST['femail'];
$password=$_POST['fpassword'];
$memails = mysql_result(mysql_query("SELECT COUNT(*) FROM Users WHERE email = '$email'"),0); //check for email exist
if($memails < 1){
echo "1";
} else {
echo "2";
}
?>