NF_Fields_Checkbox

Class NF_Fields_Checkbox.

Defined (1)

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

/includes/Fields/Checkbox.php  
  1. class NF_Fields_Checkbox extends NF_Abstracts_Input 
  2. protected $_name = 'checkbox'; 
  3.  
  4. protected $_nicename = 'Checkbox'; 
  5.  
  6. protected $_section = 'common'; 
  7.  
  8. protected $_icon = 'check-square-o'; 
  9.  
  10. protected $_type = 'checkbox'; 
  11.  
  12. protected $_templates = 'checkbox'; 
  13.  
  14. protected $_test_value = 0; 
  15.  
  16. protected $_settings = array( 'checkbox_default_value', 'checked_calc_value', 'unchecked_calc_value' ); 
  17.  
  18. protected $_settings_exclude = array( 'default', 'placeholder', 'input_limit_set' ); 
  19.  
  20. public function __construct() 
  21. parent::__construct(); 
  22.  
  23. $this->_nicename = __( 'Single Checkbox', 'ninja-forms' ); 
  24.  
  25. $this->_settings[ 'label_pos' ][ 'value' ] = 'right'; 
  26.  
  27. add_filter( 'ninja_forms_custom_columns', array( $this, 'custom_columns' ), 10, 2 ); 
  28.  
  29. add_filter( 'ninja_forms_merge_tag_value_' . $this->_name, array( $this, 'filter_merge_tag_value' ), 10, 2 ); 
  30. add_filter( 'ninja_forms_merge_tag_calc_value_' . $this->_name, array( $this, 'filter_merge_tag_value_calc' ), 10, 2 ); 
  31. add_filter( 'ninja_forms_subs_export_field_value_' . $this->_type, array( $this, 'export_value' ), 10 ); 
  32.  
  33. public function admin_form_element( $id, $value ) 
  34. $checked = ( $value ) ? "checked" : ""; 
  35.  
  36. return "<input type='hidden' name='fields[$id]' value='0' > 
  37. <input type='checkbox' name='fields[$id]' id='' $checked>"; 
  38.  
  39. public function custom_columns( $value, $field ) 
  40. if( 'checkbox' == $field->get_setting( 'type' ) ) { 
  41. if ( __( 'checked', 'ninja-forms' ) == $value || 
  42. __( 'unchecked', 'ninja-forms' ) == $value ) return $value; 
  43. $value = ( $value ) ? __( 'checked', 'ninja-forms' ) : __( 'unchecked', 'ninja-forms' ); 
  44. return $value; 
  45.  
  46. public function filter_merge_tag_value( $value, $field ) 
  47. if( $value ) { 
  48. if( isset( $field[ 'checked_calc_value' ] ) && '' != $field[ 'checked_calc_value' ] ) { 
  49. return $field['checked_calc_value']; 
  50. } else { 
  51. return __( 'checked', 'ninja-forms' ); 
  52.  
  53. if( ! $value ) { 
  54. if( isset( $field[ 'unchecked_calc_value' ] ) && '' != $field[ 'unchecked_calc_value' ] ) { 
  55. return $field['unchecked_calc_value']; 
  56. } else { 
  57. return __( 'unchecked', 'ninja-forms' ); 
  58.  
  59. return $value; 
  60.  
  61. public function filter_merge_tag_value_calc( $value, $field ) 
  62. return ( 1 == $value ) ? $field[ 'checked_calc_value' ] : $field[ 'unchecked_calc_value' ]; 
  63.  
  64. public function export_value( $value ) { 
  65. if ( __( 'checked', 'ninja-forms' ) == $value || 
  66. __( 'unchecked', 'ninja-forms' ) == $value ) return $value; 
  67. if ( $value ) { 
  68. return __( 'checked', 'ninja-forms' ); 
  69. } else { 
  70. return __( 'unchecked', 'ninja-forms' );