Conditional validation when checking checkbox group and not only one checkbox
This post was very helpful. Just an addition to this. If you are trying to check if a concrete checkbox is checked from a checkbox group then you can make it work like this.
For example lets say that we have a checkbox group that lets user indicate ways of communication. So we have email, postal mail and phone. When the user checks the phone checkbox we want the phone number input to have data.
Let's say that that phone checkbox has a value of 3. Then we would check if checkbox that indicates phone as way of communication is checked by doing the following change:
we would change this:
<?php echo((isset($_POST['callMe'])?$_POST['phoneNumber']:"(222) 222-2222")); ?>
<?php echo(in_array(3,$_POST["callMe"])?$_POST['phoneNumber']:"(222) 222-2222")); ?>
we would basicaly check to see if callMe array sends the value of 3 which would indicate that phone checkbox was checked.