If statement with checkbox multivalue...

3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 11, 2013   (RSS)

By crazyfish - April 9, 2013

Greetings,

I'm trying to add an IF statement to show or not show a button.

        <?php if ($staffRecord['section'] == 'Makeup'): ?> 
<?php endif ?>

If the checkboxes ( multivalue ) in a list - named 'section' is checked to 'makeup' don't show anything, otherwise if the section is any other checkbox show the button code. 

I seem to be missing a critical item in my programming here....  explode?  join?  take a php class?

As always, thanks for your help,

Sean

By gregThomas - April 10, 2013 - edited: April 10, 2013

Hi Sean,

A multivalue checkbox field stores the values in it in a tab separated string. This is the best way to check if a value is stored in it:

  <?php if( strstr($staffRecord['section'],"\tMakeup\t")): ?>
    Make up is checked
  <?php endif; ?>

So I'm using the PHP strstr function to search if Makeup is in the string. The \t characters will add tabs to the search string to ensure values that contain Makeup don't trigger the the if statement as well.

Thanks

Greg

Greg Thomas







PHP Programmer - interactivetools.com