/deprecated/includes/fields/list.php

  1. <?php if ( ! defined( 'ABSPATH' ) ) exit; 
  2. function ninja_forms_register_field_list() { 
  3. $args = array( 
  4. 'name' => __( 'List', 'ninja-forms' ),  
  5. 'edit_function' => 'ninja_forms_field_list_edit',  
  6. 'edit_options' => array( 
  7. array( 
  8. 'type' => 'hidden',  
  9. 'name' => 'user_info_field_group',  
  10. ),  
  11. ),  
  12. 'edit_settings' => array( 
  13. 'advanced' => array( 
  14. array( 
  15. 'type' => 'checkbox',  
  16. 'name' => 'user_state',  
  17. 'label' => __( 'This is the user\'s state', 'ninja-forms' ),  
  18. ),  
  19. ),  
  20. ),  
  21. 'display_function' => 'ninja_forms_field_list_display',  
  22. 'group' => 'standard_fields',  
  23. 'edit_label' => true,  
  24. 'edit_label_pos' => true,  
  25. 'edit_req' => true,  
  26. 'edit_custom_class' => true,  
  27. 'edit_help' => true,  
  28. 'edit_desc' => true,  
  29. 'edit_meta' => false,  
  30. 'sidebar' => 'template_fields',  
  31. 'edit_conditional' => true,  
  32. 'conditional' => array( 
  33. 'action' => array( 
  34. 'show' => array( 
  35. 'name' => __( 'Show This', 'ninja-forms' ),  
  36. 'js_function' => 'show',  
  37. 'output' => 'hide',  
  38. ),  
  39. 'hide' => array( 
  40. 'name' => __( 'Hide This', 'ninja-forms' ),  
  41. 'js_function' => 'hide',  
  42. 'output' => 'hide',  
  43. ),  
  44. 'change_value' => array( 
  45. 'name' => __( 'Selected Value', 'ninja-forms' ),  
  46. 'js_function' => 'change_value',  
  47. 'output' => 'list',  
  48. ),  
  49. 'add_value' => array( 
  50. 'name' => __( 'Add Value', 'ninja-forms' ),  
  51. 'js_function' => 'add_value',  
  52. 'output' => 'ninja_forms_field_list_add_value',  
  53. ),  
  54. 'remove_value' => array( 
  55. 'name' => __( 'Remove Value', 'ninja-forms' ),  
  56. 'js_function' => 'remove_value',  
  57. 'output' => 'list',  
  58. ),  
  59. ),  
  60. 'value' => array( 
  61. 'type' => 'list',  
  62. ),  
  63. ),  
  64. 'edit_sub_value' => 'nf_field_list_edit_sub_value',  
  65. 'sub_table_value' => 'nf_field_list_sub_table_value',  
  66. ); 
  67.  
  68. ninja_forms_register_field('_list', $args); 
  69. add_filter( 'ninja_forms_field_wrap_class', 'ninja_forms_field_filter_list_wrap_class', 10, 2 ); 
  70. add_action('ninja_forms_display_after_opening_field_wrap', 'ninja_forms_display_list_type', 10, 2); 
  71.  
  72. add_action('init', 'ninja_forms_register_field_list'); 
  73.  
  74. function ninja_forms_display_list_type( $field_id, $data ) { 
  75. $field_row = ninja_forms_get_field_by_id( $field_id ); 
  76. $field_type = $field_row['type']; 
  77. if( $field_type == '_list' ) { 
  78. if ( isset( $data['list_type'] ) ) { 
  79. $list_type = $data['list_type']; 
  80. } else{ 
  81. $list_type = ''; 
  82.  
  83. ?> 
  84. <input type="hidden" id="ninja_forms_field_<?php echo $field_id;?>_list_type" value="<?php echo $list_type;?>"> 
  85. <?php 
  86.  
  87. function ninja_forms_field_list_add_value( $field_id, $x, $conditional, $name, $id, $current = '', $field_data = '' ) { 
  88. $current_value = isset( $current['value']['value'] ) ? $current['value']['value'] : ''; 
  89. $current_label = isset( $current['value']['label'] ) ? $current['value']['label'] : ''; 
  90. $current_calc = isset ( $current['value']['calc'] ) ? $current['value']['calc'] : ''; 
  91.  
  92. $list_show_value = isset( $field_data['list_show_value'] ) ? $field_data['list_show_value'] : ''; 
  93.  
  94. _e( 'Label', 'ninja-forms' ); 
  95. ?> 
  96. <input type="text" name="<?php echo $name;?>[label]" id="<?php echo $id;?>" class="" value="<?php echo $current_label;?>"> 
  97. <?php 
  98. if( $list_show_value == 1 ) { 
  99. _e( 'Value', 'ninja-forms' ); 
  100. ?> 
  101. <input type="text" name="<?php echo $name;?>[value]" id="<?php echo $id;?>" class="ninja-forms-field-<?php echo $field_id;?>-list-option-value" value="<?php echo $current_value;?>"> 
  102. <?php 
  103. }else{ 
  104. ?> 
  105. <input type="hidden" name="<?php echo $name;?>[value]" value="_ninja_forms_no_value"> 
  106. <?php 
  107. _e( 'Calc', 'ninja-forms' ); 
  108. ?> 
  109. <input type="text" name="<?php echo $name;?>[calc]" id="<?php echo $id;?>" class="" value="<?php echo $current_calc;?>"> 
  110. <?php 
  111.  
  112.  
  113. function ninja_forms_field_list_edit( $field_id, $data ) { 
  114. global $wpdb; 
  115.  
  116. $list_type = isset( $data['list_type'] ) ? $data['list_type'] : ''; 
  117. $hidden = isset( $data['list_show_value'] ) ? $data['list_show_value'] : 0; 
  118. $multi_size = isset( $data['multi_size'] ) ? $data['multi_size'] : 5; 
  119. $default_options = array( 
  120. array( 'label' => 'Option 1', 'value' => '', 'calc' => '', 'selected' => 0 ),  
  121. array( 'label' => 'Option 2', 'value' => '', 'calc' => '', 'selected' => 0 ),  
  122. array( 'label' => 'Option 3', 'value' => '', 'calc' => '', 'selected' => 0 ),  
  123. ); 
  124.  
  125. $list_options = isset ( $data['list']['options'] ) ? $data['list']['options'] : $default_options; 
  126.  
  127. $list_type_options = array( 
  128. array('name' => __( 'Dropdown', 'ninja-forms' ), 'value' => 'dropdown'),  
  129. array('name' => __( 'Radio', 'ninja-forms' ), 'value' => 'radio'),  
  130. array('name' => __( 'Checkboxes', 'ninja-forms' ), 'value' => 'checkbox'),  
  131. array('name' => __( 'Multi-Select', 'ninja-forms' ), 'value' => 'multi'),  
  132. ); 
  133.  
  134. ninja_forms_edit_field_el_output( $field_id, 'select', __( 'List Type', 'ninja-forms' ), 'list_type', $list_type, 'wide', $list_type_options, 'widefat' ); 
  135.  
  136. ?> 
  137.  
  138. <p id="ninja_forms_field_<?php echo $field_id;?>_multi_size_p" class="description description-wide" style="<?php if($list_type != 'multi') { echo 'display:none;';}?>"> 
  139. <?php _e( 'Multi-Select Box Size', 'ninja-forms' );?>: <input type="text" id="" name="ninja_forms_field_<?php echo $field_id;?>[multi_size]" value="<?php echo $multi_size;?>"> 
  140. </p> 
  141. <span id="ninja_forms_field_<?php echo $field_id;?>_list_span" class="ninja-forms-list-span"> 
  142. <!-- <p class="description description-wide"> --> 
  143. <a href="#" id="ninja_forms_field_<?php echo $field_id;?>_list_add_option" class="ninja-forms-field-add-list-option button-secondary"><?php _e( 'Add New', 'ninja-forms' );?></a> 
  144. <a href="#TB_inline?width=640&height=530&inlineId=ninja_forms_field_<?php echo $field_id;?>_import_options_div" class="thickbox button-secondary" title="<?php _e( 'Import List Items', 'ninja-forms' ); ?>" id=""><?php _e( 'Import List Items', 'ninja-forms' );?></a> 
  145. <!-- </p> --> 
  146.  
  147. <p class="description description-wide"> 
  148. <input type="hidden" id="" name="ninja_forms_field_<?php echo $field_id;?>[list_show_value]" value="0"> 
  149. <label for="ninja_forms_field_<?php echo $field_id;?>_list_show_value"><input type="checkbox" value="1" id="ninja_forms_field_<?php echo $field_id;?>_list_show_value" name="ninja_forms_field_<?php echo $field_id;?>[list_show_value]" class="ninja-forms-field-list-show-value" <?php if(isset($data['list_show_value']) AND $data['list_show_value'] == 1) { echo "checked='checked'";}?>> 
  150. <?php _e( 'Show list item values', 'ninja-forms' );?> </label> 
  151. </p> 
  152. <div id="ninja_forms_field_<?php echo $field_id;?>_list_options" class="ninja-forms-field-list-options description description-wide"> 
  153. <input type="hidden" name="ninja_forms_field_<?php echo $field_id;?>[list][options]" value=""> 
  154. <?php 
  155. if( isset( $list_options ) AND is_array( $list_options ) AND $list_options != '' ) { 
  156. $x = 0; 
  157. foreach( $list_options as $option ) { 
  158. ninja_forms_field_list_option_output( $field_id, $x, $option, $hidden ); 
  159. $x++; 
  160. ?> 
  161.  
  162. </div> 
  163. </span> 
  164. <?php add_thickbox(); ?> 
  165. <div id="ninja_forms_field_<?php echo $field_id;?>_import_options_div" style="display:none;"> 
  166. <textarea id="test" class="list-import-textarea"></textarea> 
  167. <input type="button" class="save-list-import button-secondary" value="<?php _e( 'Import', 'ninja-forms' ); ?>" rel="<?php echo $field_id;?>"> 
  168. <input type="button" class="cancel-list-import button-secondary" value="<?php _e( 'Cancel', 'ninja-forms' ); ?>"> 
  169. <p><?php _e( 'To use this feature, you can paste your CSV into the textarea above.', 'ninja-forms' );?></p> 
  170. <p><?php _e( 'The format should look like the following:', 'ninja-forms' );?></p> 
  171. <pre> 
  172. <?php 
  173. $example1 = _x( 'Label, Value, Calc', 'Example for list importing. Leave puncation in place.', 'ninja-forms' ); 
  174. echo $example1; 
  175. echo '<br />'; 
  176. echo $example1; 
  177. echo '<br />'; 
  178. echo $example1; 
  179. ?> 
  180. </pre> 
  181.  
  182. <p><?php _e( "If you want to send an empty value or calc, you should use '' for those.", 'ninja-forms' );?></p> 
  183. <pre> 
  184. <?php 
  185. $example2 = __( 'Label', 'ninja-forms' ) . ", '', ''"; 
  186. echo $example2; 
  187. echo '<br />'; 
  188. echo $example2; 
  189. echo '<br />'; 
  190. echo $example2; 
  191. ?> 
  192. </pre> 
  193.  
  194.  
  195. </div> 
  196. <?php 
  197.  
  198. function ninja_forms_field_list_display( $field_id, $data, $form_id = '' ) { 
  199. global $wpdb, $ninja_forms_fields; 
  200.  
  201. if(isset($data['show_field'])) { 
  202. $show_field = $data['show_field']; 
  203. }else{ 
  204. $show_field = true; 
  205.  
  206. $field_class = ninja_forms_get_field_class( $field_id, $form_id ); 
  207. $field_row = ninja_forms_get_field_by_id($field_id); 
  208.  
  209. $type = $field_row['type']; 
  210. $type_name = $ninja_forms_fields[$type]['name']; 
  211.  
  212. if ( isset( $data['list_type'] ) ) { 
  213. $list_type = $data['list_type']; 
  214. } else { 
  215. $list_type = ''; 
  216.  
  217. if(isset($data['list_show_value'])) { 
  218. $list_show_value = $data['list_show_value']; 
  219. }else{ 
  220. $list_show_value = 0; 
  221.  
  222. if( isset( $data['list']['options'] ) AND $data['list']['options'] != '' ) { 
  223. $options = $data['list']['options']; 
  224. }else{ 
  225. $options = array(); 
  226.  
  227. if(isset($data['label_pos'])) { 
  228. $label_pos = $data['label_pos']; 
  229. }else{ 
  230. $label_pos = 'left'; 
  231.  
  232. if(isset($data['label'])) { 
  233. $label = $data['label']; 
  234. }else{ 
  235. $label = $type_name; 
  236.  
  237. if( isset( $data['multi_size'] ) ) { 
  238. $multi_size = $data['multi_size']; 
  239. }else{ 
  240. $multi_size = 5; 
  241.  
  242. if( isset( $data['default_value'] ) AND !empty( $data['default_value'] ) ) { 
  243. $selected_value = $data['default_value']; 
  244. }else{ 
  245. $selected_value = ''; 
  246.  
  247. $list_options_span_class = apply_filters( 'ninja_forms_display_list_options_span_class', '', $field_id ); 
  248.  
  249. switch($list_type) { 
  250. case 'dropdown': 
  251. echo apply_filters( 'ninja_forms_dropdown_open_tag', '<select name="ninja_forms_field_'.$field_id.'" id="ninja_forms_field_'.$field_id.'" class="'.$field_class.'" rel="'.$field_id.'">', $field_id, $field_class, $data, $ninja_forms_fields, $options ); 
  252. ?> 
  253. <?php 
  254. $select_placeholder = ''; 
  255. if($label_pos == 'inside') { 
  256. $select_placeholder = '<option value="">'.$label.'</option>'; 
  257. echo apply_filters( 'ninja_forms_dropdown_placeholder', $select_placeholder, $label, $label_pos, $field_id, $field_class, $data, $ninja_forms_fields, $options ); 
  258. foreach($options as $option) { 
  259.  
  260. if(isset($option['value'])) { 
  261. $value = $option['value']; 
  262. }else{ 
  263. $value = $option['label']; 
  264.  
  265. $value = htmlspecialchars( $value, ENT_QUOTES ); 
  266.  
  267. if(isset($option['label'])) { 
  268. $label = $option['label']; 
  269. }else{ 
  270. $label = ''; 
  271.  
  272. if(isset($option['display_style'])) { 
  273. $display_style = $option['display_style']; 
  274. }else{ 
  275. $display_style = ''; 
  276.  
  277. if ( isset( $option['disabled'] ) AND $option['disabled'] ) { 
  278. $disabled = 'disabled'; 
  279. }else{ 
  280. $disabled = ''; 
  281.  
  282. $label = htmlspecialchars( $label, ENT_QUOTES ); 
  283.  
  284. $label = stripslashes( $label ); 
  285.  
  286. $label = str_replace( '&', '&', $label ); 
  287.  
  288. $field_label = $data['label']; 
  289.  
  290. if($list_show_value == 0) { 
  291. $value = $label; 
  292.  
  293.  
  294. if ( $selected_value == $value OR ( is_array( $selected_value ) AND in_array( $value, $selected_value ) ) ) { 
  295. $selected = 'selected'; 
  296. }else if( ( $selected_value == '' OR $selected_value == $field_label ) AND isset( $option['selected'] ) AND $option['selected'] == 1 ) { 
  297. $selected = 'selected'; 
  298. }else{ 
  299. $selected = ''; 
  300.  
  301. ?> 
  302. <option value="<?php echo $value;?>" <?php echo $selected;?> style="<?php echo $display_style;?>" <?php echo $disabled;?>><?php echo $label;?></option> 
  303. <?php 
  304. ?> 
  305. </select> 
  306. <?php 
  307. break; 
  308. case 'radio': 
  309. $x = 0; 
  310. if( $label_pos == 'left' OR $label_pos == 'above' ) { 
  311. ?><?php 
  312.  
  313. ?><input type="hidden" name="ninja_forms_field_<?php echo $field_id;?>" value=""><span id="ninja_forms_field_<?php echo $field_id;?>_options_span" class="<?php echo $list_options_span_class;?>" rel="<?php echo $field_id;?>"><ul><?php 
  314. foreach($options as $option) { 
  315.  
  316. if(isset($option['value'])) { 
  317. $value = $option['value']; 
  318. }else{ 
  319. $value = $option['label']; 
  320.  
  321. $value = htmlspecialchars( $value, ENT_QUOTES ); 
  322.  
  323. if(isset($option['label'])) { 
  324. $label = $option['label']; 
  325. }else{ 
  326. $label = ''; 
  327.  
  328. if(isset($option['display_style'])) { 
  329. $display_style = $option['display_style']; 
  330. }else{ 
  331. $display_style = ''; 
  332.  
  333. //$label = htmlspecialchars( $label, ENT_QUOTES ); 
  334.  
  335. $label = stripslashes($label); 
  336.  
  337. if($list_show_value == 0) { 
  338. $value = $label; 
  339.  
  340. if ( $selected_value == $value OR ( is_array( $selected_value ) AND in_array( $value, $selected_value ) ) ) { 
  341. $selected = 'checked'; 
  342. }else if( $selected_value == '' AND isset( $option['selected'] ) AND $option['selected'] == 1 ) { 
  343. $selected = 'checked'; 
  344. }else{ 
  345. $selected = ''; 
  346. ?><li><label id="ninja_forms_field_<?php echo $field_id;?>_<?php echo $x;?>_label" class="ninja-forms-field-<?php echo $field_id;?>-options" style="<?php echo $display_style;?>" for="ninja_forms_field_<?php echo $field_id;?>_<?php echo $x;?>"><input id="ninja_forms_field_<?php echo $field_id;?>_<?php echo $x;?>" name="ninja_forms_field_<?php echo $field_id;?>" type="radio" class="<?php echo $field_class;?>" value="<?php echo $value;?>" <?php echo $selected;?> rel="<?php echo $field_id;?>" /><?php echo $label;?></label></li><?php 
  347. $x++; 
  348. ?></ul></span><li style="display:none;" id="ninja_forms_field_<?php echo $field_id;?>_template"><label><input id="ninja_forms_field_<?php echo $field_id;?>_" name="" type="radio" class="<?php echo $field_class;?>" value="" rel="<?php echo $field_id;?>" /></label></li> 
  349. <?php 
  350. break; 
  351. case 'checkbox': 
  352. $x = 0; 
  353. ?><input type="hidden" id="ninja_forms_field_<?php echo $field_id;?>" name="ninja_forms_field_<?php echo $field_id;?>" value=""><span id="ninja_forms_field_<?php echo $field_id;?>_options_span" class="<?php echo $list_options_span_class;?>" rel="<?php echo $field_id;?>"><ul><?php 
  354. foreach($options as $option) { 
  355.  
  356. if(isset($option['value'])) { 
  357. $value = $option['value']; 
  358. }else{ 
  359. $value = $option['label']; 
  360.  
  361. $value = htmlspecialchars( $value, ENT_QUOTES ); 
  362.  
  363. if(isset($option['label'])) { 
  364. $label = $option['label']; 
  365. }else{ 
  366. $label = ''; 
  367.  
  368. if(isset($option['display_style'])) { 
  369. $display_style = $option['display_style']; 
  370. }else{ 
  371. $display_style = ''; 
  372.  
  373. //$label = htmlspecialchars( $label, ENT_QUOTES ); 
  374.  
  375. $label = stripslashes( $label) ; 
  376.  
  377. if($list_show_value == 0) { 
  378. $value = $label; 
  379.  
  380. if( isset( $option['selected'] ) AND $option['selected'] == 1 ) { 
  381. $checked = 'checked'; 
  382.  
  383. if( is_array( $selected_value ) AND in_array($value, $selected_value) ) { 
  384. $checked = 'checked'; 
  385. }else if($selected_value == $value) { 
  386. $checked = 'checked'; 
  387. }else if( $selected_value == '' AND isset( $option['selected'] ) AND $option['selected'] == 1 ) { 
  388. $checked = 'checked'; 
  389. }else{ 
  390. $checked = ''; 
  391.  
  392. ?><li><label id="ninja_forms_field_<?php echo $field_id;?>_<?php echo $x;?>_label" class="ninja-forms-field-<?php echo $field_id;?>-options" style="<?php echo $display_style;?>"><input id="ninja_forms_field_<?php echo $field_id;?>_<?php echo $x;?>" name="ninja_forms_field_<?php echo $field_id;?>[]" type="checkbox" class="<?php echo $field_class;?> ninja_forms_field_<?php echo $field_id;?>" value="<?php echo $value;?>" <?php echo $checked;?> rel="<?php echo $field_id;?>"/><?php echo $label;?></label></li><?php 
  393. $x++; 
  394. ?></ul></span><li style="display:none;" id="ninja_forms_field_<?php echo $field_id;?>_template"><label><input id="ninja_forms_field_<?php echo $field_id;?>_" name="" type="checkbox" class="<?php echo $field_class;?>" value="" rel="<?php echo $field_id;?>" /></label></li> 
  395. <?php 
  396. break; 
  397. case 'multi': 
  398. ?> 
  399. <select name="ninja_forms_field_<?php echo $field_id;?>[]" id="ninja_forms_field_<?php echo $field_id;?>" class="<?php echo $field_class;?>" multiple size="<?php echo $multi_size;?>" rel="<?php echo $field_id;?>" > 
  400. <?php 
  401. if($label_pos == 'inside') { 
  402. ?> 
  403. <option value=""><?php echo $label;?></option> 
  404. <?php 
  405. foreach($options as $option) { 
  406.  
  407. if(isset($option['value'])) { 
  408. $value = $option['value']; 
  409. }else{ 
  410. $value = $option['label']; 
  411.  
  412. $value = htmlspecialchars( $value, ENT_QUOTES ); 
  413.  
  414. if(isset($option['label'])) { 
  415. $label = $option['label']; 
  416. }else{ 
  417. $label = ''; 
  418.  
  419. if(isset($option['display_style'])) { 
  420. $display_style = $option['display_style']; 
  421. }else{ 
  422. $display_style = ''; 
  423.  
  424. $label = htmlspecialchars( $label, ENT_QUOTES ); 
  425.  
  426. $label = stripslashes($label); 
  427.  
  428. if($list_show_value == 0) { 
  429. $value = $label; 
  430.  
  431. if(is_array($selected_value) AND in_array($value, $selected_value)) { 
  432. $selected = 'selected'; 
  433. }else if( $selected_value == '' AND isset( $option['selected'] ) AND $option['selected'] == 1 ) { 
  434. $selected = 'selected'; 
  435. }else{ 
  436. $selected = ''; 
  437.  
  438. if( $display_style == '' ) { 
  439. ?> 
  440. <option value="<?php echo $value;?>" <?php echo $selected;?>><?php echo $label;?></option> 
  441. <?php 
  442. ?> 
  443. </select> 
  444. <select id="ninja_forms_field_<?php echo $field_id;?>_clone" style="display:none;" rel="<?php echo $field_id;?>" > 
  445. <?php 
  446. $x = 0; 
  447. foreach($options as $option) { 
  448.  
  449. if(isset($option['value'])) { 
  450. $value = $option['value']; 
  451. }else{ 
  452. $value = $option['label']; 
  453.  
  454. $value = htmlspecialchars( $value, ENT_QUOTES ); 
  455.  
  456. if(isset($option['label'])) { 
  457. $label = $option['label']; 
  458. }else{ 
  459. $label = ''; 
  460.  
  461. if(isset($option['display_style'])) { 
  462. $display_style = $option['display_style']; 
  463. }else{ 
  464. $display_style = ''; 
  465.  
  466. $label = htmlspecialchars( $label, ENT_QUOTES ); 
  467.  
  468. $label = stripslashes( $label ); 
  469.  
  470. if($list_show_value == 0) { 
  471. $value = $label; 
  472.  
  473. if(is_array($selected_value) AND in_array($value, $selected_value)) { 
  474. $selected = 'selected'; 
  475. }else{ 
  476. $selected = ''; 
  477.  
  478. if( $display_style != '' ) { 
  479. ?> 
  480. <option value="<?php echo $value;?>" title="<?php echo $x;?>" <?php echo $selected;?>><?php echo $label;?></option> 
  481. <?php 
  482. $x++; 
  483. ?> 
  484. </select> 
  485. <?php 
  486. break; 
  487.  
  488. function ninja_forms_field_list_option_output($field_id, $x, $option = '', $hidden = '') { 
  489. if($hidden == 1) { 
  490. $hidden = ''; 
  491. }else{ 
  492. $hidden = 'display:none'; 
  493. if(is_array($option)) { 
  494. $label = htmlspecialchars( $option['label'] ); 
  495. $label = str_replace( '&', '&', $label ); 
  496. $value = htmlspecialchars( $option['value'] ); 
  497. $value = str_replace( '&', '&', $value ); 
  498. if ( isset ( $option['calc'] ) ) { 
  499. $calc = $option['calc']; 
  500. } else { 
  501. $calc = ''; 
  502. if( isset( $option['selected'] ) ) { 
  503. $selected = $option['selected']; 
  504. }else{ 
  505. $selected = ''; 
  506. $hide = ''; 
  507. }else{ 
  508. $label = ''; 
  509. $value = ''; 
  510. $selected = ''; 
  511. $calc = ''; 
  512. $hide = 'style="display:none;"'; 
  513. if($selected == 1) { 
  514. $selected = "checked='checked'"; 
  515.  
  516. ?> 
  517. <div id="ninja_forms_field_<?php echo $field_id;?>_list_option_<?php echo $x;?>" class="ninja-forms-field-<?php echo $field_id;?>-list-option ninja-forms-field-list-option" <?php echo $hide;?> data-field="<?php echo $field_id; ?>"> 
  518. <table class="list-options"> 
  519. <tr> 
  520. <td class="ninja-forms-delete-list-option-td"> 
  521. <a href="#" id="ninja_forms_field_<?php echo $field_id;?>_list_remove_option" class="nf-remove-list-option"><span class="dashicons dashicons-dismiss"></span></a> 
  522. </td> 
  523. <td class="ninja-forms-list-option-label-td"> 
  524. <?php _e( 'Label', 'ninja-forms' );?>: <input type="text" name="ninja_forms_field_<?php echo $field_id;?>[list][options][<?php echo $x;?>][label]" id="ninja_forms_field_<?php echo $field_id;?>_list_option_label" class="ninja-forms-field-list-option-label" value="<?php echo $label;?>"> 
  525. </td> 
  526. <td class="ninja-forms-list-option-value-td"> 
  527. <span id="ninja_forms_field_<?php echo $field_id;?>_list_option_<?php echo $x;?>_value_span" name="" class="ninja-forms-field-<?php echo $field_id;?>-list-option-value" style="<?php echo $hidden;?>"><?php _e( 'Value', 'ninja-forms' );?>: <input type="text" name="ninja_forms_field_<?php echo $field_id;?>[list][options][<?php echo $x;?>][value]" id="ninja_forms_field_<?php echo $field_id;?>_list_option_value" class="ninja-forms-field-list-option-value" value="<?php echo $value;?>"></span> 
  528. </td> 
  529. <td class="ninja-forms-list-option-calc-td"> 
  530. <?php _ex( 'Calc', 'Short for calculation', 'ninja-forms' );?>: <input type="text" name="ninja_forms_field_<?php echo $field_id;?>[list][options][<?php echo $x;?>][calc]" id="ninja_forms_field_<?php echo $field_id;?>_list_option_calc" class="ninja-forms-field-list-option-calc" value="<?php echo $calc;?>"> 
  531. </td> 
  532. <td class="ninja-forms-list-option-selected-td"> 
  533. <label for="ninja_forms_field_<?php echo $field_id;?>_options_<?php echo $x;?>_selected"><?php _e( 'Selected', 'ninja-forms' );?> <input type="hidden" value="0" name="ninja_forms_field_<?php echo $field_id;?>[list][options][<?php echo $x;?>][selected]"><input type="checkbox" value="1" name="ninja_forms_field_<?php echo $field_id;?>[list][options][<?php echo $x;?>][selected]" id="ninja_forms_field_<?php echo $field_id;?>_options_<?php echo $x;?>_selected" class="ninja-forms-field-list-option-selected" <?php echo $selected;?>></label> 
  534. </td> 
  535. <td class="ninja-forms-list-option-drag-td"> 
  536. <span class="ninja-forms-drag"><span class="dashicons dashicons-menu"></span></span> 
  537. </td> 
  538. </tr> 
  539. </table> 
  540. </div> 
  541.  
  542. <?php 
  543.  
  544. function ninja_forms_field_filter_list_wrap_class( $field_wrap_class, $field_id ) { 
  545. $field_row = ninja_forms_get_field_by_id( $field_id ); 
  546. $field_type = $field_row['type']; 
  547. if( $field_type == '_list' ) { 
  548. $field_data = $field_row['data']; 
  549. if( isset( $field_data['list_type'] ) ) { 
  550. $list_type = $field_data['list_type']; 
  551. }else{ 
  552. $list_type = ''; 
  553.  
  554. $field_wrap_class = str_replace( 'list-wrap', 'list-'.$list_type.'-wrap', $field_wrap_class ); 
  555.  
  556. return $field_wrap_class; 
  557.  
  558. // Add a filter to change the current field_value to the "selected" list elements on form load, if any exist. 
  559. function ninja_forms_field_filter_list_data( $form_id ) { 
  560. global $ninja_forms_loading, $ninja_forms_processing; 
  561.  
  562. if ( isset ( $ninja_forms_loading ) ) { 
  563. $all_fields = $ninja_forms_loading->get_all_fields(); 
  564. } else { 
  565. return false; 
  566.  
  567. // Make sure we have some fields before displaying them! 
  568. if ( ! $all_fields ) { 
  569. return; 
  570.  
  571. // Loop through all of our fields and see if we have any list fields. 
  572.  
  573. foreach( $all_fields as $field_id => $user_value ) { 
  574. $tmp_array = array(); 
  575. if ( isset ( $ninja_forms_loading ) ) { 
  576. $field = $ninja_forms_loading->get_field_settings( $field_id ); 
  577. } else { 
  578. // $field = $ninja_forms_processing->get_field_settings( $field_id ); 
  579.  
  580. $field_type = $field['type']; 
  581. $data = $field['data']; 
  582. // Check to see if we are working with a list. If so, filter the default_value 
  583. if( $field_type == '_list' && empty( $user_value ) ) { 
  584. if( isset( $data['list']['options'] ) AND is_array( $data['list']['options'] ) AND !empty( $data['list']['options'] ) ) { 
  585. foreach( $data['list']['options'] as $option ) { 
  586. if( isset( $option['selected'] ) AND $option['selected'] == 1 ) { 
  587. if( isset( $data['list_show_value'] ) AND $data['list_show_value'] == 1 ) { 
  588. $tmp_array[] = $option['value']; 
  589. }else{ 
  590. $tmp_array[] = $option['label']; 
  591. if ( empty( $tmp_array ) AND $data['list_type'] == 'dropdown' AND $data['label_pos'] != 'inside' ) { 
  592. if ( isset ( $data['list_show_value'] ) AND $data['list_show_value'] == 1 AND $data['label_pos'] != 'inside' ) { 
  593. $tmp_array[] = $data['list']['options'][0]['value']; 
  594. } else { 
  595. $tmp_array[] = $data['list']['options'][0]['label']; 
  596. if ( isset ( $ninja_forms_loading ) ) { 
  597. if ( $ninja_forms_loading->get_field_settings( $field_id ) ) { 
  598. $ninja_forms_loading->update_field_value( $field_id, $tmp_array ); 
  599. } else { 
  600. // if ( !$ninja_forms_processing->get_field_value( $field_id ) ) { 
  601. // $ninja_forms_processing->update_field_value( $field_id, $tmp_array ); 
  602. // } 
  603.  
  604. add_action( 'ninja_forms_display_pre_init', 'ninja_forms_field_filter_list_data', 8 ); 
  605.  
  606. /** 
  607. * Edit submission value output function 
  608. * 
  609. * @since 2.7 
  610. * @return void 
  611. */ 
  612. function nf_field_list_edit_sub_value( $field_id, $user_value, $field ) { 
  613. $label = $field['data']['label']; 
  614. $label_pos = $field['data']['label_pos']; 
  615. $selected_value = $user_value; 
  616. $options = $field['data']['list']['options']; 
  617.  
  618. $field_class = isset( $field['data']['class'] ) ? $field['data']['class'] : ''; 
  619.  
  620. if( isset( $field['data']['list_show_value'] ) ) { 
  621. $list_show_value = $field['data']['list_show_value']; 
  622. }else{ 
  623. $list_show_value = 0; 
  624. switch( $field['data']['list_type'] ) { 
  625. case 'dropdown': 
  626. ?> 
  627. <select name="fields[<?php echo $field_id; ?>]" id="ninja_forms_field_<?php echo $field_id;?>" class="<?php echo $field_class;?>" rel="<?php echo $field_id;?>"> 
  628. <?php 
  629. if($label_pos == 'inside') { 
  630. ?> 
  631. <option value=""><?php echo $label;?></option> 
  632. <?php 
  633. foreach( $options as $option ) { 
  634.  
  635. if(isset($option['value'])) { 
  636. $value = $option['value']; 
  637. }else{ 
  638. $value = $option['label']; 
  639.  
  640. $value = htmlspecialchars( $value, ENT_QUOTES ); 
  641.  
  642. if(isset($option['label'])) { 
  643. $label = $option['label']; 
  644. }else{ 
  645. $label = ''; 
  646.  
  647. if(isset($option['display_style'])) { 
  648. $display_style = $option['display_style']; 
  649. }else{ 
  650. $display_style = ''; 
  651.  
  652. if ( isset( $option['disabled'] ) AND $option['disabled'] ) { 
  653. $disabled = 'disabled'; 
  654. }else{ 
  655. $disabled = ''; 
  656.  
  657. $label = htmlspecialchars( $label, ENT_QUOTES ); 
  658.  
  659. $label = stripslashes( $label ); 
  660.  
  661. $label = str_replace( '&', '&', $label ); 
  662.  
  663. $field_label = $field['data']['label']; 
  664.  
  665. if($list_show_value == 0) { 
  666. $value = $label; 
  667.  
  668. if ( $selected_value == $value OR ( is_array( $selected_value ) AND in_array( $value, $selected_value ) ) ) { 
  669. $selected = 'selected'; 
  670. }else if( ( $selected_value == '' OR $selected_value == $field_label ) AND isset( $option['selected'] ) AND $option['selected'] == 1 ) { 
  671. $selected = 'selected'; 
  672. }else{ 
  673. $selected = ''; 
  674.  
  675. ?> 
  676. <option value="<?php echo $value;?>" <?php echo $selected;?> style="<?php echo $display_style;?>" <?php echo $disabled;?>><?php echo $label;?></option> 
  677. <?php 
  678. ?> 
  679. </select> 
  680. <?php 
  681. break; 
  682. case 'radio': 
  683. ?> 
  684. <input type="hidden" name="fields[<?php echo $field_id; ?>]" value=""><ul><?php 
  685. foreach($options as $option) { 
  686.  
  687. if(isset($option['value'])) { 
  688. $value = $option['value']; 
  689. }else{ 
  690. $value = $option['label']; 
  691.  
  692. $value = htmlspecialchars( $value, ENT_QUOTES ); 
  693.  
  694. if(isset($option['label'])) { 
  695. $label = $option['label']; 
  696. }else{ 
  697. $label = ''; 
  698.  
  699. if(isset($option['display_style'])) { 
  700. $display_style = $option['display_style']; 
  701. }else{ 
  702. $display_style = ''; 
  703.  
  704. $label = htmlspecialchars( $label, ENT_QUOTES ); 
  705.  
  706. $label = stripslashes($label); 
  707.  
  708. if($list_show_value == 0) { 
  709. $value = $label; 
  710.  
  711. if ( $selected_value == $value OR ( is_array( $selected_value ) AND in_array( $value, $selected_value ) ) ) { 
  712. $selected = 'checked'; 
  713. }else if( $selected_value == '' AND isset( $option['selected'] ) AND $option['selected'] == 1 ) { 
  714. $selected = 'checked'; 
  715. }else{ 
  716. $selected = ''; 
  717. ?> 
  718. <li> 
  719. <label><input id="" name="fields[<?php echo $field_id; ?>]" type="radio" class="<?php echo $field_class;?>" value="<?php echo $value;?>" <?php echo $selected;?> /><?php echo $label;?></label> 
  720. </li> 
  721. <?php 
  722.  
  723. ?></ul> 
  724. <?php 
  725. break; 
  726. case 'checkbox': 
  727.  
  728. ?><input type="hidden" name="fields[<?php echo $field_id; ?>][]" value=""><ul><?php 
  729. foreach($options as $option) { 
  730.  
  731. if(isset($option['value'])) { 
  732. $value = $option['value']; 
  733. }else{ 
  734. $value = $option['label']; 
  735.  
  736. $value = htmlspecialchars( $value, ENT_QUOTES ); 
  737.  
  738. if(isset($option['label'])) { 
  739. $label = $option['label']; 
  740. }else{ 
  741. $label = ''; 
  742.  
  743. if(isset($option['display_style'])) { 
  744. $display_style = $option['display_style']; 
  745. }else{ 
  746. $display_style = ''; 
  747.  
  748. $label = htmlspecialchars( $label, ENT_QUOTES ); 
  749.  
  750. $label = stripslashes( $label) ; 
  751.  
  752. if($list_show_value == 0) { 
  753. $value = $label; 
  754.  
  755. if( isset( $option['selected'] ) AND $option['selected'] == 1 ) { 
  756. $checked = 'checked'; 
  757.  
  758. if( is_array( $selected_value ) AND in_array($value, $selected_value) ) { 
  759. $checked = 'checked'; 
  760. }else if($selected_value == $value) { 
  761. $checked = 'checked'; 
  762. }else if( $selected_value == '' AND isset( $option['selected'] ) AND $option['selected'] == 1 ) { 
  763. $checked = 'checked'; 
  764. }else{ 
  765. $checked = ''; 
  766.  
  767. ?> 
  768. <li> 
  769. <label> 
  770. <input id="" name="fields[<?php echo $field_id; ?>][]" type="checkbox" value="<?php echo $value;?>" <?php echo $checked;?> /> <?php echo $label;?> 
  771. </label> 
  772.  
  773. </li> 
  774. <?php 
  775. ?></ul> 
  776. <?php 
  777. break; 
  778. case 'multi'; 
  779. ?> 
  780. <select name="fields[<?php echo $field_id; ?>][]" multiple size="5"> 
  781. <?php 
  782. if($label_pos == 'inside') { 
  783. ?> 
  784. <option value=""><?php echo $label;?></option> 
  785. <?php 
  786. foreach($options as $option) { 
  787.  
  788. if(isset($option['value'])) { 
  789. $value = $option['value']; 
  790. }else{ 
  791. $value = $option['label']; 
  792.  
  793. $value = htmlspecialchars( $value, ENT_QUOTES ); 
  794.  
  795. if(isset($option['label'])) { 
  796. $label = $option['label']; 
  797. }else{ 
  798. $label = ''; 
  799.  
  800. if(isset($option['display_style'])) { 
  801. $display_style = $option['display_style']; 
  802. }else{ 
  803. $display_style = ''; 
  804.  
  805. $label = htmlspecialchars( $label, ENT_QUOTES ); 
  806.  
  807. $label = stripslashes($label); 
  808.  
  809. if($list_show_value == 0) { 
  810. $value = $label; 
  811.  
  812. if(is_array($selected_value) AND in_array($value, $selected_value)) { 
  813. $selected = 'selected'; 
  814. }else if( $selected_value == '' AND isset( $option['selected'] ) AND $option['selected'] == 1 ) { 
  815. $selected = 'selected'; 
  816. }else{ 
  817. $selected = ''; 
  818.  
  819. if( $display_style == '' ) { 
  820. ?> 
  821. <option value="<?php echo $value;?>" <?php echo $selected;?>><?php echo $label;?></option> 
  822. <?php 
  823. ?> 
  824. </select> 
  825. <?php 
  826. break; 
  827.  
  828. /** 
  829. * Output our user value on the sub table 
  830. * 
  831. * @since 2.7 
  832. * @return void 
  833. */ 
  834. function nf_field_list_sub_table_value( $field_id, $user_value ) { 
  835. if ( is_array ( $user_value ) ) { 
  836. echo '<ul>'; 
  837. $max_items = apply_filters( 'nf_sub_table_user_value_max_items', 3, $field_id ); 
  838. $x = 0; 
  839.  
  840. while ( $x < $max_items && $x <= count( $user_value ) - 1 ) { 
  841. echo '<li>' . $user_value[$x] . '</li>'; 
  842. $x++; 
  843. echo '</ul>'; 
  844. } else { 
  845. $max_len = apply_filters( 'nf_sub_table_user_value_max_len', 140, $field_id ); 
  846. if ( strlen( $user_value ) > 140 ) 
  847. $user_value = substr( $user_value, 0, 140 ); 
  848.  
  849. echo nl2br( $user_value ); 
.