tags:

views:

99

answers:

1

I have a form used to void, dismiss, amend and correct citations. A void can not be done in conjucntion with a dismissal, amendment, or correction. If you need to void and amend, you complete two forms. You can however do a dismissal, amendment and/or correction on the same form. I have two arrays created based on the variables from the form. One array has the variables from the void section, the other array has all the other variables.

I am trying to create a rule that compares the void to all others. I want to be able to check if any void variables are != "" and any of the other variables are != "" and then give an error message.

if($_POST[$all_other_fields] !== "" && $_POST[$void_fields] !== "")
                {
                  $all_ok = false;
        $citation_error_msg = "Blah, Blah Blah";
                 }

What I have done, unwittingly, is stated ALL varriables from both arrays must != "". I want to say if even one variable from both arrays != "", then error message.

I am not sure how to make the comparison.

+1  A: 

So, you're saying that if a void field is filled out, throw an error if someone fills out other sections? I might restructure my form into a paged form, where you ask what the user wishes to do and then present them with a specific form to do it. Having extraneous fields on a form just makes things confusing for the user.

In any event, if you stick with your current form design, you'll need to have an array of void field names against which you'll check your $_POST. Something like:

$vf_flag=false;
$void_fields=array('vf1','vf2','vf3');
    foreach($void_fields as $vf) {
      if(!isset($_POST[$vf])) continue;
      $vf_flag=true;
      break; //only need one error
    }
$nonvf_flag=false;
//do the same as above except with a non_voidfields array()

if($nonvf_flag && $vf_flag) $citation_msg='blah blah blah';

This is a verbose way, but it's straightforward. You could also do it with array_filter() and a callback.

dnagirl
George Garman
dnagirl
Thank you for explaining that. I have gone over it and over it, and I even used your variable names but I am getting the following error:PHP Fatal error: Cannot break/continue 1 level in D:\Resume\eCitation\Civil_VDAC_Validation.php on line 77Line 77 is the first Break; That is occurring with the form fields empty, if that matters.
George Garman
@George-Garman : If you are getting an error like 'Cannot break/continue 1 level' it is because the break is not inside a control structure like foreach, while or switch (`if` doesn't count). See http://ca3.php.net/break. Lastly, I just noticed a syntax error in my code on the `if(!isset` I'm missing the closing parenthesis. Sorry about that.
dnagirl