I'm having problems with error reporting on a query form on our website.
Everything is working correctly except that if they miss a mandatory field, the error reporting kicks but when the error message displays, it's right at the bottom of the form.
I have tried moving that section of the php script but that doesn't work correctly.
Here is the php code for the error coding.
$page = $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
if (!ereg($page, $_SERVER['HTTP_REFERER']))
$errors[] = "Invalid referer";
if (!$_POST['Name'])
$errors[] = "Your name is required";
if (!$_POST['Email'])
$errors[] = " An Email address is required";
if (!$_POST['Address'])
$errors[] = "An Address is required";
if (!$_POST['Phone'])
$errors[] = "Your Phone number is required";
if (count($errors)>0) {
foreach($errors as $err)
echo "$err<br>\n";
echo "<br>Please use your browser's Back button to fix.";
} else
?>
I left out the rest cause there was no need for it here
What I am trying to do is either move the error message up (so they don't need to scroll down to see it or have a popup with what fields they left out.
Unfortunately, we will need to see the form, along with the code to help you "move" the output. No other way around it. I know what has to be moved, and I can tell you. If your script is not laid out like I think it should be, then you're just going to be massively confused. Along with possibly causing yourself more headache than is worthwhile. When just a simple posting of the entire script (minus any passwords, or usernames) would sort this problem quickly, efficiently, and without the normal hum,drum of us guessing where the script lies withing the boundaries of the php opening and closing tags.
If you would like to skip the above paragraph, here is the short form.
Quote:
I left out the rest cause there was no need for it here
Quite the opposite, if you cannot get the output where you want it, and you can see the whole script, then how are we suppose to put the output correctly for you with only a few lines.
$page = $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
if (!ereg($page, $_SERVER['HTTP_REFERER']))
$errors[] = "Invalid referer";
// check to see if a name was entered
if (!$_POST['Name'])
$errors[] = "Your name is required";
if (!$_POST['Email'])
$errors[] = " An Email address is required";
if (!$_POST['Address'])
$errors[] = "An Address is required";
if (!$_POST['Phone'])
$errors[] = "Your Phone number is required";
if (count($errors)>0) {
foreach($errors as $err)
echo "$err<br>\n";
echo "<br>Please use your browser's Back button to fix.";
} else {
$page = $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; if (!ereg($page, $_SERVER['HTTP_REFERER'])) $errors[] = "Invalid referer";
// check to see if a name was entered if (!$_POST['Name']) $errors[] = "Your name is required"; if (!$_POST['Email']) $errors[] = " An Email address is required"; if (!$_POST['Address']) $errors[] = "An Address is required"; if (!$_POST['Phone']) $errors[] = "Your Phone number is required";
$error_messages = NULL; if(count($errors)>0) { $error_messages=implode('<br />',$errors)."<br />Please use your browser's Back button to fix."; } else {
//add the $_POST back to the form on the event that the process fails, this way the individual will
//not have to hit their back button to get the form, AND it is already filled out for them. This will
//make for a happier user base.
Sorry I haven't gotten back to say thanks, so thanks for all the help, my only question is how do I add the $_POST, is it like this?
I've made a form which contains 2 types of account i.e Student and Teacher. I've validated that if the fields remain empty the validation works out and doesnt let the form get submit. I've coded on the Teacher's radio button that when it'll be checked so the COURSE drop down menu should be disabled. But I've a problem that when it gets disable but again validation asks for course selection in Teacher Type Account.. I want that in Teacher Type Account the course validation should run and let the form get submit.....