/deprecated/includes/display/fields/display-fields.php

  1. <?php if ( ! defined( 'ABSPATH' ) ) exit; 
  2. /** 
  3. * Outputs the HTML for each field within a given form_id. 
  4. * It is attached to the ninja_forms_display_fields hook which is excuted by ninja_forms_display_form() in display-form.php 
  5. **/ 
  6. add_action('init', 'ninja_forms_register_display_fields'); 
  7. function ninja_forms_register_display_fields() { 
  8. add_action('ninja_forms_display_fields', 'ninja_forms_display_fields', 10, 2); 
  9.  
  10. function ninja_forms_display_fields($form_id) { 
  11. global $ninja_forms_fields, $ninja_forms_loading, $ninja_forms_processing; 
  12.  
  13. $field_results = ninja_forms_get_fields_by_form_id($form_id); 
  14. $field_results = apply_filters('ninja_forms_display_fields_array', $field_results, $form_id); 
  15.  
  16. if ( is_array ( $field_results ) AND !empty ( $field_results ) ) { 
  17. foreach ( $field_results as $field ) { 
  18. if ( isset ( $ninja_forms_loading ) && $ninja_forms_loading->get_form_ID() == $form_id ) { 
  19. $field = $ninja_forms_loading->get_field_settings( $field['id'] ); 
  20. } else if ( isset ( $ninja_forms_processing ) && $ninja_forms_processing->get_form_ID() == $form_id ) { 
  21. $field = $ninja_forms_processing->get_field_settings( $field['id'] ); 
  22.  
  23. if( isset( $ninja_forms_fields[$field['type']] ) ) { 
  24. $type = $ninja_forms_fields[$field['type']]; 
  25.  
  26. $field_id = $field['id']; 
  27. if(isset($field['data']['req'])) { 
  28. $req = $field['data']['req']; 
  29. }else{ 
  30. $req = ''; 
  31.  
  32. $default_label_pos = $type['default_label_pos']; 
  33. $display_wrap = $type['display_wrap']; 
  34. $display_label = $type['display_label']; 
  35. $sub_edit_function = $type['sub_edit_function']; 
  36. $display_function = $type['display_function']; 
  37.  
  38. //Check to see if we are currently editing a form submission. 
  39. //If we are, then $display_function should be set to the sub_edit_function instead. 
  40. if( is_object( $ninja_forms_processing)) { 
  41. $sub_id = $ninja_forms_processing->get_form_setting('sub_id'); 
  42. }else if(isset($_REQUEST['sub_id'])) { 
  43. $sub_id = absint( $_REQUEST['sub_id'] ); 
  44. }else{ 
  45. $sub_id = ''; 
  46.  
  47. if ( $sub_id != '' AND $sub_edit_function != '' AND is_admin() ) { 
  48. $display_function = $sub_edit_function; 
  49.  
  50. $process_field = $type['process_field']; 
  51. $data = $field['data']; 
  52.  
  53.  
  54. //These filters can be used to temporarily modify the settings of a field, i.e. default_value. 
  55. $data = apply_filters( 'ninja_forms_field', $data, $field_id ); 
  56. //Check the show_field value of our $data array. If it is set to false, don't output the field. 
  57. if(isset($data['show_field'])) { 
  58. $show_field = $data['show_field']; 
  59. }else{ 
  60. $show_field = true; 
  61.  
  62. if( isset( $data['display_style'] ) ) { 
  63. $display_style = $data['display_style']; 
  64. }else{ 
  65. $display_style = ''; 
  66.  
  67. if( isset( $data['visible'] ) ) { 
  68. $visible = $data['visible']; 
  69. }else{ 
  70. $visible = true; 
  71.  
  72. if ( $display_style != '' ) { 
  73. $display_style = 'style="'.$display_style.'"'; 
  74.  
  75. if ( $display_function != '' AND $show_field ) { 
  76. if ( isset( $data['label_pos'] ) ) { 
  77. $label_pos = $data['label_pos']; 
  78. }else{ 
  79. $label_pos = ''; 
  80. if( $label_pos == '' ) { 
  81. $label_pos = $default_label_pos; 
  82.  
  83. do_action( 'ninja_forms_display_before_field', $field_id, $data ); 
  84.  
  85. //Check to see if display_wrap has been disabled. If it hasn't, show the wrapping DIV. 
  86. if($display_wrap) { 
  87. $field_wrap_class = ninja_forms_get_field_wrap_class($field_id, $form_id); 
  88. $field_wrap_class = apply_filters( 'ninja_forms_field_wrap_class', $field_wrap_class, $field_id ); 
  89. do_action( 'ninja_forms_display_before_opening_field_wrap', $field_id, $data ); 
  90. ?> 
  91. <div class="<?php echo $field_wrap_class;?>" <?php echo $display_style;?> id="ninja_forms_field_<?php echo $field_id;?>_div_wrap" data-visible="<?php echo $visible;?>"> 
  92. <?php 
  93. do_action( 'ninja_forms_display_after_opening_field_wrap', $field_id, $data ); 
  94.  
  95. //Check to see if display_label has been disabled. If it hasn't, show the label. 
  96. if( $display_label ) { 
  97. if( $label_pos == 'left' OR $label_pos == 'above' ) { // Check the label position variable. If it is left or above, show the label. 
  98. do_action( 'ninja_forms_display_before_field_label', $field_id, $data ); 
  99. do_action( 'ninja_forms_display_field_label', $field_id, $data ); 
  100. do_action( 'ninja_forms_display_after_field_label', $field_id, $data ); 
  101.  
  102. //Check to see if there is a registered display function. If so, call it. 
  103. if($display_function != '') { 
  104.  
  105. do_action( 'ninja_forms_display_before_field_function', $field_id, $data ); 
  106. $arguments['field_id'] = $field_id; 
  107. $arguments['data'] = $data; 
  108. $arguments['form_id'] = $form_id; 
  109. call_user_func_array($display_function, $arguments); 
  110. do_action( 'ninja_forms_display_after_field_function', $field_id, $data ); 
  111. if( $label_pos == 'left' OR $label_pos == 'inside') { 
  112. do_action( 'ninja_forms_display_field_help', $field_id, $data ); 
  113.  
  114. //Check to see if display_label has been disabled. If it hasn't, show the label. 
  115. if($display_label) { 
  116. if($label_pos == 'right' OR $label_pos == 'below') { // Check the label position variable. If it is right or below, show the label. 
  117. do_action( 'ninja_forms_display_before_field_label', $field_id, $data ); 
  118. do_action( 'ninja_forms_display_field_label', $field_id, $data ); 
  119. do_action( 'ninja_forms_display_after_field_label', $field_id, $data ); 
  120.  
  121. //Check to see if display_wrap has been disabled. If it hasn't close the wrapping DIV 
  122. if($display_wrap) { 
  123. do_action( 'ninja_forms_display_before_closing_field_wrap', $field_id, $data ); 
  124. ?> 
  125. </div> 
  126. <?php 
  127. do_action( 'ninja_forms_display_after_closing_field_wrap', $field_id, $data ); 
  128. do_action( 'ninja_forms_display_after_field', $field_id, $data ); 
  129.  
  130. /** 
  131. * The next two functions are used to get CSS class names based upon field settings. 
  132. * 
  133. **/ 
  134.  
  135. function ninja_forms_get_field_wrap_class( $field_id, $form_id = '' ) { 
  136. global $ninja_forms_loading, $ninja_forms_processing; 
  137. $field_wrap_class = 'field-wrap'; 
  138.  
  139. if ( '' == $form_id ) { 
  140. $field = ninja_forms_get_field_by_id( $field_id ); 
  141. $form_id = $field['form_id']; 
  142.  
  143. if ( isset ( $ninja_forms_loading ) && $ninja_forms_loading->get_form_ID() == $form_id ) { 
  144. $field_row = $ninja_forms_loading->get_field_settings( $field_id ); 
  145. } else if ( isset ( $ninja_forms_processing ) && $ninja_forms_processing->get_form_ID() == $form_id ) { 
  146. $field_row = $ninja_forms_processing->get_field_settings( $field_id ); 
  147.  
  148. $form_id = $field_row['form_id']; 
  149. $data = $field_row['data']; 
  150.  
  151. if ( isset ( $field_row['type'] ) ) { 
  152. $type_slug = $field_row['type']; 
  153. } else { 
  154. $type_slug = ''; 
  155.  
  156. if(strpos($type_slug, "_") === 0) { 
  157. $type_slug = substr($type_slug, 1); 
  158.  
  159. $field_wrap_class .= " ".$type_slug."-wrap"; 
  160. if(isset($data['label_pos'])) { 
  161. $label_pos = $data['label_pos']; 
  162. }else{ 
  163. $label_pos = 'above'; 
  164. $field_wrap_class .= " label-".$label_pos; 
  165.  
  166. $x = 0; 
  167. $custom_class = ''; 
  168.  
  169. if(isset($data['class']) AND !empty($data['class'])) { 
  170. $class_array = explode(", ", $data['class']); 
  171. foreach($class_array as $class) { 
  172. $custom_class .= $class; 
  173. if($x != (count($class_array) - 1)) { 
  174. $custom_class .= " "; 
  175. $x++; 
  176.  
  177. if($custom_class != '') { 
  178. $custom_class = str_replace( ' ', '-wrap ', $custom_class ); 
  179. $field_wrap_class .= ' '.$custom_class.'-wrap'; 
  180.  
  181. if( is_object( $ninja_forms_processing) AND is_array($ninja_forms_processing->get_errors_by_location($field_id))) { 
  182. foreach($ninja_forms_processing->get_errors_by_location($field_id) as $error) { 
  183. $field_wrap_class .= ' ninja-forms-error'; 
  184. break; 
  185. return apply_filters( 'ninja_forms_display_field_wrap_class', $field_wrap_class, $field_id, $field_row ); 
  186.  
  187.  
  188. function ninja_forms_get_field_class( $field_id, $form_id = '' ) { 
  189. global $ninja_forms_loading, $ninja_forms_processing; 
  190.  
  191. if ( '' == $form_id ) { 
  192. $field = ninja_forms_get_field_by_id( $field_id ); 
  193. $form_id = $field['form_id']; 
  194.  
  195. if ( isset ( $ninja_forms_loading ) && $ninja_forms_loading->get_form_ID() == $form_id ) { 
  196. $field_row = $ninja_forms_loading->get_field_settings( $field_id ); 
  197. $field_class = $ninja_forms_loading->get_field_setting( $field_id, 'field_class' ); 
  198. } else if ( isset ( $ninja_forms_processing ) && $ninja_forms_processing->get_form_ID() == $form_id ) { 
  199. $field_row = $ninja_forms_processing->get_field_settings( $field_id ); 
  200. $field_class = $ninja_forms_processing->get_field_setting( $field_id, 'field_class' ); 
  201.  
  202. $field_data = $field_row['data']; 
  203. $field_data = apply_filters( 'ninja_forms_field', $field_data, $field_id ); 
  204.  
  205. $field_type = isset ( $field_row['type'] ) ? $field_row['type'] : ''; 
  206.  
  207. $x = 0; 
  208. $custom_class = ''; 
  209.  
  210. if ( isset( $field_data['class'] ) AND !empty ( $field_data['class'] ) ) { 
  211. $class_array = explode(", ", $field_data['class']); 
  212. foreach($class_array as $class) { 
  213. $custom_class .= $class; 
  214. if($x != (count($class_array) - 1)) { 
  215. $custom_class .= " "; 
  216. $x++; 
  217.  
  218. $req_class = ''; 
  219. if(isset($field_data['req']) AND $field_data['req'] == 1) { 
  220. $req_class = 'ninja-forms-req'; 
  221.  
  222. // Check to see if we are dealing with a field that has the user_info_field_group set. 
  223. if ( isset ( $field_data['user_info_field_group_name'] ) and $field_data['user_info_field_group_name'] != '' ) { 
  224. $user_info_group_class = $field_data['user_info_field_group_name'].'-address'; 
  225. } else { 
  226. $user_info_group_class = ''; 
  227.  
  228. $address_class = ''; 
  229. // Check to see if we are dealing with an address field. 
  230. if ( isset ( $field_data['user_address_1'] ) and $field_data['user_address_1'] == 1 ) { 
  231. $address_class = 'address address1'; 
  232. }  
  233.  
  234. if ( isset ( $field_data['user_address_2'] ) and $field_data['user_address_2'] == 1 ) { 
  235. $address_class = 'address address2'; 
  236. }  
  237.  
  238. if ( isset ( $field_data['user_city'] ) and $field_data['user_city'] == 1 ) { 
  239. $address_class = 'address city'; 
  240. }  
  241.  
  242. if ( isset ( $field_data['user_state'] ) and $field_data['user_state'] == 1 ) { 
  243. $address_class = 'address state'; 
  244.  
  245. if ( isset ( $field_data['user_zip'] ) and $field_data['user_zip'] == 1 ) { 
  246. $address_class = 'address zip'; 
  247.  
  248. if ( '_country' == $field_type ) { 
  249. $address_class = 'address country'; 
  250.  
  251. if($req_class != '') { 
  252. $field_class .= " ".$req_class; 
  253.  
  254. if($custom_class != '') { 
  255. $field_class .= " ".$custom_class; 
  256.  
  257. if ( $user_info_group_class != '' ) { 
  258. $field_class .= " ".$user_info_group_class; 
  259.  
  260. if ( $address_class != '' ) { 
  261. $field_class .= " ".$address_class; 
  262.  
  263. if ( isset ( $field_data['input_limit'] ) and $field_data['input_limit'] != '' ) { 
  264. $field_class .= " input-limit"; 
  265.  
  266. return apply_filters( 'ninja_forms_display_field_class', $field_class, $field_id, $field_row ); 
.