think it can be as simple as:
if (($field != "Apartment_Number") && ($field != "Middle_Initial"))
( using AND &&, instead of OR || )
But this will not cover the case when BOTH those are empty.
For this you will need to add a $flag that tells that BOTH A_N and M_I are empty
and give a message that BOTH can not be empty.
What can complicate things, is when we test 2 cases in 1 IF
and then try to do something more.
if (($field != "Apartment_Number") && ($field != "Middle_Initial"))
Often is more clean coding to test each case, for itself.
We can maybe later, when this code with larger number of lines is working
find good ways to make it shorter.
Having looked at many a experienced good PHP Programmers code
I often find they prefer Not To Do too much at each line.
And it works!
/* Check for blanks */
foreach($_POST as $field => $value)
{
$ap_blank = false;
$mi_blank = false;
if ($field == "Apartment_Number") {
if(is blank){
$ap_blank = true;
}
}
elseif ($field == "Middle_Initial"){
if(is blank){
$mi_blank = true;
}
}
else{ //neither of those 2 fields
//do this check
}
}
// Evaluate for eventual messages
if($ap_blank && $mi_blank){
$error_msg = 'You cant leave both blank, my friend';
}
elseif(anything else blank){
$error_msg = 'another message';
}
else{
// we have a happy case of Correctly Submitted FORM !!!!!!
}
cheers!