mercredi 20 avril 2016

PHP Save multiple checkbox values

I'm making a theme options for Wordpress and i'm trying to create a multiple checkbox option in one settings field. However only one checkbox value is being saved. After some searching around I've realized that multiple checkboxes need to be saved differently then single checkboxes. But i can't seem to find a straight answer on how to do this.

Here's my markup.

<div class="checkbox-toggle">
    <input id="show_date" type="checkbox" value="1" name="mbpanel_display_section_options[show_meta]" <?php if(1 == $options['show_meta']) echo 'checked="checked"'; ?> />
    <label for="show_date"><div><span>Off</span><span>On</span></div></label>
    <p class="input-description">Date</p>
</div>
<div class="checkbox-toggle">
    <input id="show_author" type="checkbox" value="2" name="mbpanel_display_section_options[show_meta]" <?php if(2 == $options['show_meta']) echo 'checked="checked"'; ?> />
    <label for="show_author"><div><span>Off</span><span>On</span></div></label>
    <p class="input-description">Author</p>
</div>

That's how i've been doing it for single checkboxes. So my question is how can i save all of the checkboxes that get submitted and echo the checked value on them ? From what i've researched i need to save the values in an array and check if it's in the array but i'm not experienced with php so don't fully understand what i'm doing. Any help would be greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire