I have a 'List (text)' field set up with five options displayed as a series of checkboxes.
I would like the last of these checkboxes to control the visibility of a button in the node template.
<?php if($node->field_the_checkbox_field['und']['value'] == 'key_of_checkbox'): ?> // do stuff <?php endif; ?>
The problem with the above is that it only works when this checkbox is the only one selected, otherwise it is no longer the '' result.
How could I go about checking all of the potential five checkboxes for my result?
I thought I'd found a horribly verbose workaround by checking every offset one by one like so:
<?php if($node->field_the_checkbox_field['und']['value'] == 'key_of_checkbox' || $node->field_the_checkbox_field['und']['value'] == 'key_of_checkbox' || $node->field_the_checkbox_field['und']['value'] == 'key_of_checkbox'): ?> // do stuff <?php endif; ?>
etc... but, now I get an 'undefined offset' error for each offset that doesn't exist, ie. not all of the boxes will ever be checked, and so there are never usually five results, meaning that when only two of these checkboxes are checked offsets 2 - 4 don't exist. PHP doesn't like that, apparently.
I'm wondering if my problem here is that I should be using five boolean checkboxes, which at least will always return a result one way or another. That seemed messy when I was planning this out, but now it's looking ever more inviting!
Since I'm short on time, I decided to go with my thoughts above and base my conditionals on single points of data which can either return me a 'true' or 'false' status. My PHP (as you can probably see above) is crappy to say the least - far too crappy to work out how to get around this one. I'd be interested if anyone has any ideas regarding this though!
Thanks for reading.
EXTRA EDITS for clarity and grammar