Caldera_Forms_Field_Input

Class for creating input field element HTML.

Defined (1)

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

/classes/field/input.php  
  1. class Caldera_Forms_Field_Input extends Caldera_Forms_Field_HTML{ 
  2.  
  3. /** 
  4. * @inheritdoc 
  5. */ 
  6. public static function html( array $field, array $field_structure, array $form, $value = null ) { 
  7. $type = Caldera_Forms_Field_Util::get_type( $field ); 
  8. $field_base_id = Caldera_Forms_Field_Util::get_base_id( $field, null, $form ); 
  9. if ( null === $value ) { 
  10. if( ! empty( $field_structure [ 'field_value' ] ) ) { 
  11. $value = Caldera_Forms::do_magic_tags( $field_structure [ 'field_value' ], null, $form ); 
  12. }else{ 
  13. $value = self::find_default( $field, $form ); 
  14.  
  15.  
  16.  
  17.  
  18. $sync = $syncer = $default = false; 
  19. if( in_array( $type, self::sync_fields() ) ) { 
  20. $syncer = Caldera_Forms_Sync_Factory::get_object( $form, $field, $field_base_id ); 
  21. $sync = $syncer->can_sync(); 
  22. $default = $syncer->get_default(); 
  23.  
  24. if( 'text' == $type && !empty( $field['config']['type_override'] ) ) { 
  25. $type = $field['config']['type_override']; 
  26. $required = ''; 
  27.  
  28. $field_classes = Caldera_Forms_Field_Util::prepare_field_classes( $field, $form ); 
  29. $mask = self::get_mask_string( $field ); 
  30. $place_holder = self::place_holder_string( $field ); 
  31. $attrs = array( 
  32. 'type' => $type,  
  33. 'data-field' =>$field[ 'ID'],  
  34. 'class' => $field_classes[ 'field' ],  
  35. 'id' => $field_base_id,  
  36. 'name' => $field_structure['name'],  
  37. 'value' => $value,  
  38. 'data-type' => $type 
  39. ); 
  40.  
  41.  
  42. if( ! empty( $field[ 'hide_label' ] ) && empty( $place_holder ) ) { 
  43. $place_holder = self::place_holder_string( $field, $field[ 'label' ] ); 
  44.  
  45. if( 'number' == $type ) { 
  46. foreach( array( 
  47. 'min',  
  48. 'max',  
  49. 'step' 
  50. ) as $index ) { 
  51. if( isset( $field[ 'config' ][ $index ] ) && ( 0 === $field[ 'config' ][ $index ] || '0' === $field[ 'config' ][ $index ] || ! empty( $field[ 'config' ][ $index ] ) )) { 
  52. $attrs[ $index ] = $field[ 'config' ][ $index ]; 
  53. $attrs[ 'data-parsley-type' ] = 'number'; 
  54. }elseif ( 'phone_better' == $type ) { 
  55. $attrs[ 'type' ] = 'tel'; 
  56. }elseif ( 'credit_card_number' == $type ) { 
  57. $attrs[ 'type' ] = 'tel'; 
  58. $attrs[ 'class' ][] = 'cf-credit-card '; 
  59. $attr[ 'data-parsley-creditcard' ] = Caldera_Forms_Field_Util::credit_card_types( $field, $form ); 
  60. }elseif( 'credit_card_exp' == $type ) { 
  61. $attrs[ 'type' ] = 'tel'; 
  62. $attr[ 'data-parsley-creditcard' ] = ''; 
  63. }elseif ( 'credit_card_cvv' == $type ) { 
  64. $attrs[ 'type' ] = 'tel'; 
  65. $attr[ 'data-parsley-creditcard' ] = ''; 
  66.  
  67. if( $field_structure['field_required'] ) { 
  68. $required = 'required'; 
  69. $attrs[ 'aria-required' ] = 'true'; 
  70.  
  71. if( $sync ) { 
  72. $attrs[ 'data-binds' ] = wp_json_encode( $syncer->get_binds() ); 
  73. $attrs[ 'data-sync' ] = $default; 
  74.  
  75. $attr_string = caldera_forms_field_attributes( 
  76. $attrs,  
  77. $field,  
  78. $form 
  79. ); 
  80.  
  81. $aria = self::aria_string( $field_structure ); 
  82.  
  83. return '<input ' . $place_holder . ' ' . $mask . ' ' . $required . ' ' . $attr_string . ' ' . $aria .' >'; 
  84.  
  85.  
  86. /** 
  87. * Defined which fields use sync 
  88. * @sine 1.5.0 
  89. * @return array 
  90. */ 
  91. protected static function sync_fields() { 
  92. return array( 
  93. 'text',  
  94. 'email',  
  95. 'html',  
  96. 'number',  
  97. 'hidden',  
  98. 'url',  
  99. 'phone_better',  
  100. 'paragraph' 
  101. ); 
  102.  
  103.  
  104. /** 
  105. * Get input mask config string 
  106. * @since 1.5.0 
  107. * @param array $field 
  108. * @return string 
  109. */ 
  110. protected static function get_mask_string( array $field ) { 
  111. $mask = ''; 
  112. if ( 'phone' != Caldera_Forms_Field_Util::get_type( $field ) ) { 
  113. if ( ! empty( $field[ 'config' ][ 'masked' ] ) ) { 
  114. $mask = "data-inputmask=\"'mask': '" . $field[ 'config' ][ 'mask' ] . "'\" "; 
  115. } else { 
  116. $mask = '(999)999-9999'; 
  117. if( $field['config']['type'] == 'international' ) { 
  118. $mask = '+99 99 999 9999'; 
  119. }elseif ( $field['config']['type'] == 'custom' ) { 
  120. $mask = $field['config']['custom']; 
  121.  
  122. return $mask; 
  123.  
  124.