Title: On/off Switch
Last modified: August 30, 2016

---

# On/off Switch

 *  Resolved [Zain Sohail](https://wordpress.org/support/users/zainsohail19/)
 * (@zainsohail19)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/onoff-switch/)
 * Is there any field type available by which I could use simple on and off option?
 * For example, I would like to give user the option to Enable Notifications or 
   Disable them ..
 * The button could be similar to: [http://take.ms/Ud4S5](http://take.ms/Ud4S5)
 * Thanks ..
 * [https://wordpress.org/plugins/cmb2/](https://wordpress.org/plugins/cmb2/)

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

 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [10 years, 5 months ago](https://wordpress.org/support/topic/onoff-switch/#post-6898232)
 * Should be able to be done with radio buttons and enough CSS customization.
 *  Thread Starter [Zain Sohail](https://wordpress.org/support/users/zainsohail19/)
 * (@zainsohail19)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/onoff-switch/#post-6898253)
 * Thanks for the reply Michael. Well I tried to create a custom field and while
   I was able to render the markup, the post was not saving the meta data.
 * The code I used is given below:
 *     ```
       function cmb2_render_onoffswitch( $field, $escaped_value, $object_id, $object_type, $field_type_object ) {
   
       	?>
       	<div class="onoffswitch">
       	<?php echo $field_type_object->input( array( 'type' => 'checkbox', 'class' => 'onoffswitch-checkbox', 'name' => 'onoffswitch', 'id' => 'myonoffswitch', 'value' => 'onoffswitch' ) ); ?>
       	    <label class="onoffswitch-label" for="myonoffswitch">
       	        <span class="onoffswitch-inner"></span>
       	        <span class="onoffswitch-switch"></span>
       	    </label>
       	</div>
       	<?php
   
       }
       add_action( 'cmb2_render_onoffswitch', 'cmb2_render_onoffswitch', 10, 5 );
       ```
   
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [10 years, 5 months ago](https://wordpress.org/support/topic/onoff-switch/#post-6898300)
 * I’d recommend a radio button over a checkbox, that way the user can only choose
   one or the other.
 * Is the for the frontend or the backend? If frontend, you may need to do the saving
   of the meta yourself, if I recall right. Check the blogpost link below specifically
   for this.
 * Some resources to try and get you better on your way:
    [https://github.com/WebDevStudios/CMB2/wiki](https://github.com/WebDevStudios/CMB2/wiki)
   [https://github.com/WebDevStudios/CMB2-Snippet-Library](https://github.com/WebDevStudios/CMB2-Snippet-Library)
   [https://webdevstudios.com/2015/03/30/use-cmb2-to-create-a-new-post-submission-form/](https://webdevstudios.com/2015/03/30/use-cmb2-to-create-a-new-post-submission-form/)

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

The topic ‘On/off Switch’ 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/)

 * 3 replies
 * 2 participants
 * Last reply from: [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * Last activity: [10 years, 5 months ago](https://wordpress.org/support/topic/onoff-switch/#post-6898300)
 * Status: resolved