cf_handle_multi_view

The Caldera Forms cf handle multi view function.

Description

cf_handle_multi_view( $data, $field ); 

Parameters (2)

0. $data
The data.
1. $field
The field.

Usage

  1. if ( !function_exists( 'cf_handle_multi_view' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'caldera-forms/includes/field_processors.php'; 
  3.  
  4. // The data. 
  5. $data = null; 
  6.  
  7. // The field. 
  8. $field = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = cf_handle_multi_view($data, $field); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/field_processors.php  
  1. function cf_handle_multi_view( $data, $field ) { 
  2.  
  3. if( empty( $data ) || !is_array( $data ) ) { 
  4. return $data; 
  5. // can put in the value as well. 
  6. $viewer = array(); 
  7.  
  8. foreach( $data as $key=>$value ) { 
  9.  
  10. foreach( $field['config']['option'] as $option_key=>$option ) { 
  11. if( $value == $option['value'] ) { 
  12. $viewer[$key] = $option['label'] . ' (' . $option['value'] . ')'; 
  13. if( !isset( $viewer[$key] ) ) { 
  14. $viewer[$key] = $value; 
  15.  
  16. return implode( ', ', $viewer ); 
  17.