I have 3 featured product panels on the homepage, and I'm writing a CMS page for it. I'm trying to validate the items.
They are selected via three <select>
elements, featured1
, featured2
and featured3
. The default is <option value="0" selected>Select an element</option>
I need to validate the $_POST
to ensure that the user hasn't selected the same product for more than one of the panels.
I have worked out that each $_POST
needs to be $_POST['featuredN'] > 0
but I can't seem to find a logical way of processing the 7 potential outcomes. Using a logic table, where 1 is a set value.
1 2 3
-------
0 0 0
1 1 1
1 0 0
0 1 0
0 0 1
1 1 0
0 1 1
If an item is 0, then I will not update it, but I want the user to be able to update a single item if needs be.
I cannot find a logical way to see if the item is not 0, and then compare it to another item if that also is not 0.
So far my colleague suggested, adding up the values. Which works to see if condition 1 0 0 0
is not met.
I have a vague feeling that some form of recursive function might be in order, but I can't quite get my brain to help me on this one! So to the collective brain! :)