CMB2::show_form PHP Method

show_form() public method

Loops through and displays fields
Since: 1.0.0
public show_form ( integer $object_id, string $object_type = '' )
$object_id integer Object ID
$object_type string Type of object being saved. (e.g., post, user, or comment)
    public function show_form($object_id = 0, $object_type = '')
    {
        $this->render_form_open($object_id, $object_type);
        foreach ($this->prop('fields') as $field_args) {
            $this->render_field($field_args);
        }
        $this->render_form_close($object_id, $object_type);
    }

Usage Example

 /**
  * Displays form markup
  * @since  0.1.3
  * @param  int  $term_id Term ID
  */
 public function display_form($term_id)
 {
     if (!class_exists('CMB2')) {
         return;
     }
     $this->do_override_filters($term_id);
     $object_id = $this->id($term_id);
     // Hard-code object ID
     $this->cmb->object_id($object_id);
     // Hard-code object type
     $this->cmb->object_type('options-page');
     // Enqueue JS/CSS
     if ($this->cmb->prop('cmb_styles')) {
         CMB2_hookup::enqueue_cmb_css();
     }
     if ($this->cmb->prop('enqueue_js')) {
         CMB2_hookup::enqueue_cmb_js();
     }
     // Add object id to the form for easy access
     printf('<input type="hidden" name="term_opt_name" value="%s">', $object_id);
     printf('<input type="hidden" name="object_id" value="%s">', $object_id);
     // Show cmb form
     $this->cmb->show_form();
 }