hello i have the following problem:
i have a form in that i would like to check via php for some input errors. beside that i would like to display an user information about whats being wrong.
the problem i have is, that i only like to display one message and not all at same time. therefor i need to filter all error messages from php to limit that to one.
so php is looking for this:
<?php if (isset($errors['for_a']):?><div id="errormessage">some text</div><?php endif; ?>
and the php rule is:
(case1) ... if ( isset($errors['for_a']) AND (!isset($errors['for_b'])) AND (!isset($errors['for_c'])) OR (!isset($errors['for_d'])) ...
OR
(case 2) ...AND (!isset($errors['for_b'])) AND (!isset($errors['for_c'])) AND (!isset($errors['for_d'])) ...
and so on for input field a...
so the problem is that i have 7 input fields and this would mean i have to write all possibilities. is there a way to shorten this?
thanks a lot.
UPDATE:
okay, maybe its not clear enough what i like to achieve.
i do not have problems displaying the error message. this works fine. each error message for each specific input field could be displayed correctly.
the problem is that i have different error messages for each of it. i do store that in a more dimensional array:
if(empty($a)){$errors['a'][]="first failure for a"}
if(something else happens($a)){$errors['a'][]="second failure for a"}
...
if(empty($b)){$errors['b'][]="first failure for b"}
if(something else happens($b)){$errors['b'][]="second failure for b"}
...
displaying that error messages is also not the problem.
<?php if (isset($errors['a'])):?>
<?php echo "<div class='erl'>";
echo $errors['a'][0];
echo "</div>";
endif;?>
<?php endif;?>
the problem is the conditions for displaying only one error message at same time!
so here are some graphics to show what i mean:
this is the situation at the moment, all error divs will be displayed at the same time:

this is what i like to achieve, that only one error message will be displayed at the same time start checking by the first input field:

so that user will be forced to correct the first input field before displaying the second error layer:

hope it gets clear now.
I’m not sure what you’re asking. Usually with forms, if you have lots of fields you can create an array of errors, and either display the errors as a bullet list at the top of the form, or inline with its corresponding form element.
You’ll now have an
$errorsarray. If it’s not empty, your form had errors. You can then display these errors in one of two ways. As a bullet list at the top of your form:Or inline with each form field:
Hope that helps.