Hi I'm trying to create a simple registration form with ajax validation. I've got the form working almost how I'd like... a message appears on the page with the errors for each field entered incorrectly.
The problem is all the error messages appear in one div together and I would like to have each field have its own div containing only its own error.
I think I need to wrap my error messages in xml and use something like this -
What is the format of responseText?
Where are the error messages displayed exactly?
The response Text is just being echoed out in a php page. And I have the validation error messages displaying all in one div on the form page so when the user hit the submit button they stay on the page, their form data is not lost and the error messages appear... I would just like to have each error message appear in its own div positioned next to its relevant form field.
As you can see I've got the fname information commented out right now and my messaging is working for lname but as soon as I uncomment the fname stuff in hopes to send a message for both lname and fname nothing happens I don't understand why.
header('Content-Type: text/xml');
$errors = array();
$lname = mysql_real_escape_string($_POST['lname']);
//$fname = mysql_real_escape_string($_POST['fname']);
if($lname == NULL) {
$errors[] = "<lname>NEED TO FILL</lname>";
}
$errmsg = "";
$errcount = count($errors);
if($errcount > 0) {
echo "The following errors occurred when your form was submitted:<br /><br />";
for($i=0; $i< $errcount; $i++) {
$errmsg .= $errors[$i]."<br />";
}
echo $errmsg;
}
else {
echo " ";
}
This is what I had to start with but I can't seem to get it working I'd really like to have the individual error messages returned as XML and displayed in separate divs.
Bookmarks