ninja_forms_display_js

The Ninja Forms ninja forms display js function.

Description

ninja_forms_display_js( $form_id, (string) $local_vars = '' ); 

Parameters (2)

0. $form_id
The form id.
1. $local_vars — Optional. (string) => ''
The local vars.

Usage

  1. if ( !function_exists( 'ninja_forms_display_js' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/display/scripts.php'; 
  3.  
  4. // The form id. 
  5. $form_id = null; 
  6.  
  7. // The local vars. 
  8. $local_vars = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = ninja_forms_display_js($form_id, $local_vars); 
  12.  

Defined (1)

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

/deprecated/includes/display/scripts.php  
  1. function ninja_forms_display_js( $form_id, $local_vars = '' ) { 
  2. global $post, $ninja_forms_display_localize_js, $wp_locale, $ninja_forms_loading, $ninja_forms_processing; 
  3.  
  4. if ( defined( 'NINJA_FORMS_JS_DEBUG' ) && NINJA_FORMS_JS_DEBUG ) { 
  5. $suffix = ''; 
  6. $src = 'dev'; 
  7. } else { 
  8. $suffix = '.min'; 
  9. $src = 'min'; 
  10.  
  11. // Get all of our form fields to see if we need to include the datepicker and/or jqueryUI 
  12. $datepicker = 0; 
  13. $qtip = 0; 
  14. $mask = 0; 
  15. $currency = 0; 
  16. $input_limit = 0; 
  17. $rating = 0; 
  18. $calc_value = array(); 
  19. $calc_fields = array(); 
  20. $calc_eq = false; 
  21. $sub_total = false; 
  22. $tax = false; 
  23.  
  24. $fields = ninja_forms_get_fields_by_form_id( $form_id ); 
  25.  
  26. if( is_array( $fields ) AND !empty( $fields ) ) { 
  27. foreach( $fields as $field ) { 
  28.  
  29. if ( isset ( $field['id'] ) ) { 
  30. $field_id = $field['id']; 
  31. } else { 
  32. $field_id = ''; 
  33.  
  34. if ( isset ( $field['type'] ) ) { 
  35. $field_type = $field['type']; 
  36. } else { 
  37. $field_type = ''; 
  38.  
  39. $field['data'] = apply_filters( 'ninja_forms_display_script_field_data', $field['data'], $field_id ); 
  40. if( isset( $field['data']['datepicker'] ) AND $field['data']['datepicker'] == 1 ) { 
  41. $datepicker = 1; 
  42.  
  43. if( isset( $field['data']['show_help'] ) AND $field['data']['show_help'] == 1 ) { 
  44. $qtip = 1; 
  45.  
  46. if( isset( $field['data']['mask'] ) AND $field['data']['mask'] != '' ) { 
  47. $mask = 1; 
  48.  
  49. if( isset( $field['data']['mask'] ) AND $field['data']['mask'] == 'currency' ) { 
  50. $currency = 1; 
  51.  
  52. if( isset( $field['data']['input_limit'] ) AND $field['data']['input_limit'] != '' ) { 
  53. $input_limit = $field['data']['input_limit']; 
  54. $input_limit_type = $field['data']['input_limit_type']; 
  55.  
  56. if( $field_type == '_rating' ) { 
  57. $rating = 1; 
  58.  
  59. // Populate an array of calculation values for the form fields. 
  60. // Check to see if this field has a calc_value. If it does, add this to our calc_value array so that we can tell what it is in our JS. 
  61. if ( isset( $field['data']['calc_value'] ) ) { 
  62. $calc_value[$field_id] = $field['data']['calc_value']; 
  63. } else if ( $field_type == '_list' ) { 
  64. // Get a list of options and their 'calc' setting. 
  65. if ( isset ( $field['data']['list']['options'] ) AND is_array ( $field['data']['list']['options'] ) ) { 
  66. $list_options = $field['data']['list']['options']; 
  67. foreach ( $list_options as $option ) { 
  68. if ( isset ( $field['data']['list_show_value'] ) AND $field['data']['list_show_value'] == 1 ) { 
  69. $key = $option['value']; 
  70. } else { 
  71. $key = $option['label']; 
  72. if ( !isset ( $option['calc'] ) OR ( isset ( $option['calc'] ) AND empty ( $option['calc'] ) ) ) { 
  73. $option['calc'] = 0; 
  74. $calc_value[$field_id][$key] = $option['calc']; 
  75.  
  76. // Check to see if this is a tax field; 
  77. if ( $field_type == '_tax' ) { 
  78. $tax = $field_id; 
  79.  
  80. // Check to see if this is a calculation field. If it is, store it in our calc_fields array along with its method. 
  81. if ( $field_type == '_calc' ) { 
  82. if ( isset ( $field['data']['calc_method'] ) ) { 
  83. $calc_method = $field['data']['calc_method']; 
  84. } else { 
  85. $calc_method = 'auto'; 
  86.  
  87. // Check to see if this is a sub_total calculation 
  88. if ( isset ( $field['data']['payment_sub_total'] ) AND $field['data']['payment_sub_total'] == 1 ) { 
  89. $sub_total = $field_id; 
  90.  
  91. switch ( $calc_method ) { 
  92. case 'auto': 
  93. $calc_fields[$field_id] = array( 'method' => 'auto' ); 
  94. break; 
  95. case 'fields': 
  96. $field_ops = $field['data']['calc']; 
  97. $calc_fields[$field_id] = array( 'method' => 'fields', 'fields' => $field_ops ); 
  98. break; 
  99. case 'eq': 
  100. $calc_fields[$field_id] = array( 'method' => 'eq', 'eq' => $field['data']['calc_eq'] ); 
  101. $calc_eq = true; 
  102. break; 
  103.  
  104. $calc_fields[$field_id]['places'] = $field['data']['calc_places']; 
  105.  
  106. // Loop through our fields again looking for calc fields that are totals. 
  107. foreach( $fields as $field ) { 
  108.  
  109. if ( isset ( $field['id'] ) ) { 
  110. $field_id = $field['id']; 
  111. } else { 
  112. $field_id = ''; 
  113.  
  114. if ( isset ( $field['type'] ) ) { 
  115. $field_type = $field['type']; 
  116. } else { 
  117. $field_type = ''; 
  118.  
  119. if ( $field_type == '_calc' ) { 
  120.  
  121. if ( isset ( $field['data']['payment_total'] ) AND $field['data']['payment_total'] == 1 ) { 
  122. if ( $sub_total AND $tax AND $field['data']['calc_method'] == 'auto' ) { 
  123.  
  124. $calc_fields[$field_id]['method'] = 'eq'; 
  125. $calc_fields[$field_id]['eq'] = 'field_'.$sub_total.' + ( field_'.$sub_total.' * field_'.$tax.' )'; 
  126. $calc_eq = true; 
  127.  
  128. // Loop through our fields once more to add them to our calculation field with the method of 'eq'. 
  129. if ( $calc_eq ) { 
  130. foreach ( $calc_fields as $calc_id => $calc ) { 
  131. if( $calc['method'] == 'eq' ) { 
  132. foreach( $fields as $field ) { 
  133. $field_id = $field['id']; 
  134.  
  135. if (preg_match("/\bfield_".$field_id."\b/i", $calc['eq'] ) ) { 
  136. $calc_fields[$calc_id]['fields'][] = $field_id; 
  137.  
  138. if ( $datepicker == 1 ) { 
  139. wp_enqueue_script( 'jquery-ui-datepicker' ); 
  140.  
  141. if ( $qtip == 1 ) { 
  142. wp_enqueue_script( 'jquery-qtip',  
  143. NINJA_FORMS_URL .'js/min/jquery.qtip.min.js',  
  144. array( 'jquery', 'jquery-ui-position' ) ); 
  145.  
  146. if ( $mask == 1 ) { 
  147. wp_enqueue_script( 'jquery-maskedinput',  
  148. NINJA_FORMS_URL .'js/min/jquery.maskedinput.min.js',  
  149. array( 'jquery' ) ); 
  150.  
  151. if ( $currency == 1 ) { 
  152. wp_enqueue_script('jquery-autonumeric',  
  153. NINJA_FORMS_URL .'js/min/autoNumeric.min.js',  
  154. array( 'jquery' ) ); 
  155.  
  156. if ( $input_limit != 0 ) { 
  157. wp_enqueue_script('jquery-char-input-limit',  
  158. NINJA_FORMS_URL .'js/min/word-and-character-counter.min.js',  
  159. array( 'jquery' ) ); 
  160.  
  161. if ( $rating == 1 ) { 
  162. wp_enqueue_script('jquery-rating',  
  163. NINJA_FORMS_URL .'js/min/jquery.rating.min.js',  
  164. array( 'jquery' ) ); 
  165.  
  166. $form_row = ninja_forms_get_form_by_id($form_id); 
  167. $form_row = apply_filters( 'ninja_forms_display_form_form_data', $form_row ); 
  168. if( isset( $form_row['data']['ajax'] ) ) { 
  169. $ajax = $form_row['data']['ajax']; 
  170. }else{ 
  171. $ajax = 0; 
  172.  
  173. if( isset( $form_row['data']['hide_complete'] ) ) { 
  174. $hide_complete = $form_row['data']['hide_complete']; 
  175. }else{ 
  176. $hide_complete = 0; 
  177.  
  178. if( isset( $form_row['data']['clear_complete'] ) ) { 
  179. $clear_complete = $form_row['data']['clear_complete']; 
  180. }else{ 
  181. $clear_complete = 0; 
  182.  
  183. $ninja_forms_js_form_settings['ajax'] = $ajax; 
  184. $ninja_forms_js_form_settings['hide_complete'] = $hide_complete; 
  185. $ninja_forms_js_form_settings['clear_complete'] = $clear_complete; 
  186.  
  187. $calc_settings['calc_value'] = ''; 
  188. $calc_settings['calc_fields'] = ''; 
  189.  
  190. if ( !empty ( $calc_value ) ) { 
  191. $calc_settings['calc_value'] = $calc_value; 
  192.  
  193. $calc_settings['calc_fields'] = $calc_fields; 
  194.  
  195. $plugin_settings = nf_get_settings(); 
  196. if(isset($plugin_settings['date_format'])) { 
  197. $date_format = $plugin_settings['date_format']; 
  198. }else{ 
  199. $date_format = 'm/d/Y'; 
  200.  
  201. $date_format = ninja_forms_date_to_datepicker($date_format); 
  202.  
  203. $datepicker_args = array(); 
  204. if ( !empty( $date_format ) ) { 
  205. $datepicker_args['dateFormat'] = $date_format; 
  206.  
  207. $currency_symbol = $plugin_settings['currency_symbol']; 
  208.  
  209. $password_mismatch = esc_html(stripslashes($plugin_settings['password_mismatch'])); 
  210.  
  211. $msg_format = 'inline'; 
  212.  
  213. wp_enqueue_script( 'ninja-forms-display',  
  214. NINJA_FORMS_URL . 'js/' . $src .'/ninja-forms-display' . $suffix . '.js?nf_ver=' . NF_PLUGIN_VERSION,  
  215. array( 'jquery', 'jquery-form', 'backbone', 'underscore' ) ); 
  216.  
  217. if( !isset( $ninja_forms_display_localize_js ) OR !$ninja_forms_display_localize_js ) { 
  218. wp_localize_script( 'ninja-forms-display', 'ninja_forms_settings', array('ajax_msg_format' => $msg_format, 'password_mismatch' => $password_mismatch, 'plugin_url' => NINJA_FORMS_URL, 'datepicker_args' => apply_filters( 'ninja_forms_forms_display_datepicker_args', $datepicker_args ), 'currency_symbol' => $currency_symbol, 'date_format' => $date_format ) ); 
  219. $ninja_forms_display_localize_js = true; 
  220. wp_localize_script( 'ninja-forms-display', 'thousandsSeparator', addslashes( $wp_locale->number_format['thousands_sep'] ) ); 
  221. wp_localize_script( 'ninja-forms-display', 'decimalPoint', addslashes( $wp_locale->number_format['decimal_point'] ) ); 
  222.  
  223. wp_localize_script( 'ninja-forms-display', 'ninja_forms_form_'.$form_id.'_settings', apply_filters( 'nf_form_js_settings', $ninja_forms_js_form_settings, $form_id ) ); 
  224. wp_localize_script( 'ninja-forms-display', 'ninja_forms_form_'.$form_id.'_calc_settings', $calc_settings ); 
  225.  
  226. wp_localize_script( 'ninja-forms-display', 'ninja_forms_password_strength', array( 
  227. 'empty' => __( 'Strength indicator', 'ninja-forms' ),  
  228. 'short' => __( 'Very weak', 'ninja-forms' ),  
  229. 'bad' => __( 'Weak', 'ninja-forms' ),  
  230. /** translators: password strength */ 
  231. 'good' => _x( 'Medium', 'password strength', 'ninja-forms' ),  
  232. 'strong' => __( 'Strong', 'ninja-forms' ),  
  233. 'mismatch' => __( 'Mismatch', 'ninja-forms' ) 
  234. ) ); 
  235.