The following code snippet is returning 'failed' alert box even thought the form is filled out correctly, I would like to display the 'passed' alert box. Surely there is something wrong but I can;t find where...
Full code here: http://alessandrosantese.com/Forms/Custom_Validation/Form-Validation-Plugin-AJAX.html
submit.click(function(evt) {
evt.preventDefault();
validate_form();
$('form input:not(.submit, .email, .test)').each(function(){
if ($(this).val() == '') {
add_color($(this), red);
}
else {
add_color($(this), white);
}
});
var data = form.serialize();
// AJAX call
$.ajax({
url: 'process.php',
type: "post",
data: data,
success: function(r){
if (r.success) {
alert('passed');
} else {
alert('failed');
}
}
});
});
PHP code (very basic, for now just to get the AJAX success working)
<?php
$name = $_POST['f_name'];
$l_name = $_POST['l_name'];
$email1 = $_POST['email'];
$email2 = $_POST['email_c'];
$tel = $_POST['tel'];
$postcode = $_POST['postcode'];
$url = $_POST['url'];
$checkbox = $_POST['checkbox'];
echo "\n$name\n$l_name\n$email1\n$email2\n$tel\n$postcode\n$url\n$checkbox";
?>
I need to find a way to make sure that validate_form(); worked before the AJAX call itself.
echoshould be sending back JSON encoded data, not just a list of NL separated strings.