Title: Multicheck Selected Values Problem
Last modified: August 31, 2016

---

# Multicheck Selected Values Problem

 *  Resolved [sadeepa17](https://wordpress.org/support/users/sadeepa17/)
 * (@sadeepa17)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/multicheck-selected-values-problem/)
 * I have a custom form using cmb2. User submit information which gets then stored
   on related Events Calendar Pro plugin fields. All works fine and gets stored 
   fine but the selceted values of a multicheck.
    I’m doing this
 *     ```
       $cmb->add_field( array(
       		'name'    => __( 'Special Acts', 'xtensionpress' ),
       		'id'      => 'special_acts',
       		'desc' => __( 'Check all that apply.', 'xtensionpress' ),
       		'type'    => 'multicheck',
       		//'multiple' => true, // Store values in individual rows
       		'options' => array(
       			'Field1' => __( 'Field1', 'xtensionpress' ),
       			'Field2' => __( 'Field2', 'xtensionpress' ),
       			'Field3' => __( 'Field3', 'xtensionpress' ),
       			'Field4' => __( 'Field4', 'xtensionpress' ),
       		),
       		'inline'  => true, // Toggles display to inline
       	) );
       ```
   
 * Then to save selected values to related Events Calendar field I do this
 *     ```
       if ( isset( $sanitized_values['special_acts'] ) ) {
       		update_post_meta( $new_submission_id, '_ecp_custom_8', $sanitized_values['special_acts'] );
       	}
       ```
   
 * where _ecp_custom_8 is the Events Calendar checkbox field.
 * When the form with the above code is run, the special_acts multicheck field is
   there and when submitting the form all seems to go fine: no errors, all other
   fields type correctly save their values to their related Events Calendar fields,
   but the _ecp_custom_8 field shows all the checkboxes unchecked.
 * I’ve tried to uncomment the _multiple_ attribute and still no success. The _ecp_custom_8
   Events Calendar field is a checkbox; its name and values match the _special\_acts_
   one. Am I missing something?
 * [https://wordpress.org/plugins/cmb2/](https://wordpress.org/plugins/cmb2/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [10 years, 1 month ago](https://wordpress.org/support/topic/multicheck-selected-values-problem/#post-7320782)
 * Can you share what value gets saved to the _ecp_custom_8 field? My hunch is that
   the multiple fields are coming in possibly as a concatenated string of values
   for the checkboxes, but when trying to output the saved values back to the string,
   they’re not being separated out again for the individual fields, thus it’s not
   finding any matches to make checks for.
 *  Thread Starter [sadeepa17](https://wordpress.org/support/users/sadeepa17/)
 * (@sadeepa17)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/multicheck-selected-values-problem/#post-7320801)
 * Hi Michael and thanks for your support. I’m literally bumping my head in the 
   wall about this and it is greatly delaying my schedule on this project, so I 
   really hope you can help me.
 * How would I check what valued gets saved to the _ecp_custom_8 field? In database
   nothing get stored for _ecp_custom_8. On the Events Calendar Pro submitted event
   I just get the 4 checkboxes for _ecp_custom_8 field unchecked, no matter what
   I checked on cmb2 form submission. Is there another type of check that I could
   make to give you more info?
 *  Plugin Author [Justin Sternberg](https://wordpress.org/support/users/jtsternberg/)
 * (@jtsternberg)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/multicheck-selected-values-problem/#post-7320803)
 * On the Events Calendar Pro submitted event, check the checkboxes, click save,
   then look in the database to see how it stores the data. Ultimately you will 
   need to translate the CMB2 submitted data into whatever format it stores to the
   database natively.
 *  Thread Starter [sadeepa17](https://wordpress.org/support/users/sadeepa17/)
 * (@sadeepa17)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/multicheck-selected-values-problem/#post-7320808)
 * Ok Justin, Thanks. I’ve done as you suggested. I have saved the _ecp_custom_8
   checking Field1 and Field4 and saved. Then on database it shows:
 * MetaKey: _ecp_custom_8
    MetaValue: Field1|Field4
 *  Thread Starter [sadeepa17](https://wordpress.org/support/users/sadeepa17/)
 * (@sadeepa17)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/multicheck-selected-values-problem/#post-7320810)
 * Sorry double post
 *  Thread Starter [sadeepa17](https://wordpress.org/support/users/sadeepa17/)
 * (@sadeepa17)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/multicheck-selected-values-problem/#post-7320826)
 * Just in case I was misunderstood, I haven’t solved my problem; I’ve just posted
   how the _ecp_custom_8 field stores the values in db. Any help would be greatly
   appreciated.
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [10 years, 1 month ago](https://wordpress.org/support/topic/multicheck-selected-values-problem/#post-7320853)
 * Do your CMB2 fields have values of “Field1” and “Field4” for how it’s set up?
 * Looks like it’s getting glued together by the “|” character for the actual saving
   to the `_ecp_custom_8` field.
 * The next step here would be to intercept things before the render of the field/
   checkboxes, grab the `_ecp_custom_8` field, and use php’s `explode` function 
   to turn the saved value back into an array.
 *     ```
       $data = 'Field1|Field4'
       $parts = explode( '|', $data );
       ```
   
 * Very pseudocode as I don’t know off the top of my head how Events Calendar fetches
   the fields, or perhaps how you’re intending to. The $parts variable would be 
   an array with indexed values of ‘Field1’ and ‘Field4’ now. You could then use
   those to determine if each field should be checked or not.
 * It’s a bit of manual work, I realize, but it’s what must be done sometimes.
 *  Thread Starter [sadeepa17](https://wordpress.org/support/users/sadeepa17/)
 * (@sadeepa17)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/multicheck-selected-values-problem/#post-7320860)
 * Thank you Michael, that helped.
 * I have solved with
 *     ```
       if ( isset( $sanitized_values['special_acts'] ) ) {
                       $ecpCbox = implode("|",$sanitized_values['special_acts']);
       		update_post_meta( $new_submission_id, '_ecp_custom_8', $ecpCbox );
       	}
       ```
   
 * And now it works. Thank you for addressing me into the right direction, guys.
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [10 years, 1 month ago](https://wordpress.org/support/topic/multicheck-selected-values-problem/#post-7320861)
 * Welcome.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Multicheck Selected Values Problem’ is closed to new replies.

 * ![](https://ps.w.org/cmb2/assets/icon.svg?rev=2866672)
 * [CMB2](https://wordpress.org/plugins/cmb2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cmb2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cmb2/)
 * [Active Topics](https://wordpress.org/support/plugin/cmb2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cmb2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cmb2/reviews/)

## Tags

 * [sanitized](https://wordpress.org/support/topic-tag/sanitized/)
 * [update_post_meta](https://wordpress.org/support/topic-tag/update_post_meta/)
 * [values](https://wordpress.org/support/topic-tag/values/)

 * 9 replies
 * 3 participants
 * Last reply from: [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * Last activity: [10 years, 1 month ago](https://wordpress.org/support/topic/multicheck-selected-values-problem/#post-7320861)
 * Status: resolved