I have implemented jquery validation engine plugin for form validations. The problem is with ajax validation for input. Whenever the form is submitted or submit button is clicked before the ajax success message is shown, it is redirecting to same page, which means the php script on form submit is not calling.
eg:
I have a email field
<input class="validate[required,ajax[EmailCallPhp]]" type="text" name="email" />
When we enter the email and click submit button immediately before and any success/error if the ajax returns false form is not submitted but if its successful, it submits the form but the php script on form submit does not work and redirects to same page..
$(document).ready(function(){
$("#RegFb").validationEngine();
});
code calls ajax:
"EmailCallPhp": {
"url": "valEmail.php", //register email validation
// you may want to pass extra data on the ajax call
"extraData": "name=eric",
// if you provide an "alertTextOk", it will show as a green prompt when the field validates
"alertTextOk": "* OK",
"alertText": "* Email Already Exist",
"alertTextLoad": "* Validating, please wait"
}
valEmail.php code
$email=$_REQUEST['fieldValue'];
$emailId=$_REQUEST['fieldId'];
$validateError= "This username is already taken";
$validateSuccess= "This username is available";
/* RETURN VALUE */
$arrayToJs = array();
$arrayToJs[0] = $emailId;
$stmt = $db->prepare("SELECT email FROM table WHERE email = :email");
$stmt->execute(array(':email'=>$email));
if($stmt->rowCount() == 0){ // validate??
$arrayToJs[1] = true; // RETURN TRUE
echo json_encode($arrayToJs); // RETURN ARRAY WITH success
}else{
for($x=0;$x<1000000;$x++){
if($x == 990000){
$arrayToJs[1] = false;
echo json_encode($arrayToJs); // RETURN ARRAY WITH ERROR
}
}
}
Thanks!