/deprecated/includes/fields/textbox.php

  1. <?php if ( ! defined( 'ABSPATH' ) ) exit; 
  2. function ninja_forms_register_field_textbox() { 
  3. $args = array( 
  4. 'name' => __( 'Textbox', 'ninja-forms' ),  
  5. 'sidebar' => 'template_fields',  
  6. 'edit_options' => array( 
  7.  
  8. array( 
  9. 'type' => 'hidden',  
  10. 'name' => 'first_name',  
  11. ),  
  12. array( 
  13. 'type' => 'hidden',  
  14. 'name' => 'last_name',  
  15. ),  
  16. array( 
  17. 'type' => 'hidden',  
  18. 'name' => 'user_address_1',  
  19. ),  
  20. array( 
  21. 'type' => 'hidden',  
  22. 'name' => 'user_address_2',  
  23. ),  
  24. array( 
  25. 'type' => 'hidden',  
  26. 'name' => 'user_city',  
  27. ),  
  28. array( 
  29. 'type' => 'hidden',  
  30. 'name' => 'user_zip',  
  31. ),  
  32. array( 
  33. 'type' => 'hidden',  
  34. 'name' => 'user_phone',  
  35. ),  
  36. array( 
  37. 'type' => 'hidden',  
  38. 'name' => 'user_email',  
  39. ),  
  40. array( 
  41. 'type' => 'hidden',  
  42. 'name' => 'user_info_field_group',  
  43. 'default' => 1,  
  44. ),  
  45.  
  46. ),  
  47. 'edit_settings' => array( 
  48. 'restrictions' => array( 
  49. array( 
  50. 'type' => 'checkbox',  
  51. 'name' => 'email',  
  52. 'label' => __( 'Validate as an email address? (Field must be required)', 'ninja-forms' ),  
  53. ),  
  54. array( 
  55. 'type' => 'checkbox',  
  56. 'label' => __( 'Disable Input', 'ninja-forms' ),  
  57. 'name' => 'disable_input',  
  58. ),  
  59. ),  
  60. 'advanced' => array( 
  61. array( 
  62. 'type' => 'checkbox',  
  63. 'name' => 'datepicker',  
  64. 'label' => __( 'Datepicker', 'ninja-forms' ),  
  65. ),  
  66. array( 
  67. 'type' => 'checkbox',  
  68. 'label' => __( 'This is the user\'s state', 'ninja-forms' ),  
  69. 'name' => 'user_state',  
  70. ),  
  71. ),  
  72. ),  
  73. 'display_function' => 'ninja_forms_field_text_display',  
  74. 'save_function' => '',  
  75. 'group' => 'standard_fields',  
  76. 'edit_label' => true,  
  77. 'edit_label_pos' => true,  
  78. 'edit_req' => true,  
  79. 'edit_custom_class' => true,  
  80. 'edit_help' => true,  
  81. 'edit_desc' => true,  
  82. 'edit_meta' => false,  
  83. 'edit_conditional' => true,  
  84. 'edit_autocomplete_off' => true,  
  85. 'conditional' => array( 
  86. 'value' => array( 
  87. 'type' => 'text',  
  88. ),  
  89. ),  
  90. 'pre_process' => 'ninja_forms_field_text_pre_process',  
  91. 'edit_sub_value' => 'nf_field_text_edit_sub_value',  
  92. 'sub_table_value' => 'nf_field_text_sub_table_value',  
  93. 'edit_placeholder' => true,  
  94. ); 
  95.  
  96. ninja_forms_register_field( '_text', $args ); 
  97.  
  98. add_action( 'init', 'ninja_forms_register_field_textbox' ); 
  99.  
  100. function nf_field_text_edit_default_value( $field_id, $data ) { 
  101. $field = ninja_forms_get_field_by_id( $field_id ); 
  102. if ( '_text' != $field['type'] ) 
  103. return false; 
  104.  
  105. $plugin_settings = nf_get_settings(); 
  106.  
  107. $currency_symbol = isset( $plugin_settings['currency_symbol'] ) ? $plugin_settings['currency_symbol'] : "$"; 
  108. $date_format = isset( $plugin_settings['date_format'] ) ? $plugin_settings['date_format'] : "m/d/Y"; 
  109. $default_value = isset( $data['default_value'] ) ? $data['default_value'] : ''; 
  110. $default_value_type = isset( $data['default_value_type'] ) ? $data['default_value_type'] : ''; 
  111. $custom = ''; 
  112.  
  113. if( $default_value == 'none' ) { 
  114. $default_value = ''; 
  115.  
  116. ?> 
  117. <div class="description description-thin"> 
  118. <span class="field-option"> 
  119. <label for=""> 
  120. <?php _e( 'Default Value' , 'ninja-forms'); ?> 
  121. </label><br /> 
  122. <select id="default_value_<?php echo $field_id;?>" name="ninja_forms_field_<?php echo $field_id;?>[default_value_type]" class="widefat ninja-forms-_text-default-value"> 
  123. <option value="" <?php if( $default_value == '') { echo 'selected'; $custom = 'no';}?>><?php _e('None', 'ninja-forms'); ?></option> 
  124. <option value="_user_id" <?php if($default_value == '_user_id') { echo 'selected'; $custom = 'no';}?>><?php _e('User ID (If logged in)', 'ninja-forms'); ?></option> 
  125. <option value="_user_firstname" <?php if($default_value == '_user_firstname') { echo 'selected'; $custom = 'no';}?>><?php _e('User Firstname (If logged in)', 'ninja-forms'); ?></option> 
  126. <option value="_user_lastname" <?php if($default_value == '_user_lastname') { echo 'selected'; $custom = 'no';}?>><?php _e('User Lastname (If logged in)', 'ninja-forms'); ?></option> 
  127. <option value="_user_display_name" <?php if($default_value == '_user_display_name') { echo 'selected'; $custom = 'no';}?>><?php _e('User Display Name (If logged in)', 'ninja-forms'); ?></option> 
  128. <option value="_user_email" <?php if($default_value == '_user_email') { echo 'selected'; $custom = 'no';}?>><?php _e('User Email (If logged in)', 'ninja-forms'); ?></option> 
  129. <option value="post_id" <?php if($default_value == 'post_id') { echo 'selected'; $custom = 'no';}?>><?php _e('Post / Page ID (If available)', 'ninja-forms'); ?></option> 
  130. <option value="post_title" <?php if($default_value == 'post_title') { echo 'selected'; $custom = 'no';}?>><?php _e('Post / Page Title (If available)', 'ninja-forms'); ?></option> 
  131. <option value="post_url" <?php if($default_value == 'post_url') { echo 'selected'; $custom = 'no';}?>><?php _e('Post / Page URL (If available)', 'ninja-forms'); ?></option> 
  132. <option value="today" <?php if($default_value == 'today') { echo 'selected'; $custom = 'no';}?>><?php _e('Today\'s Date', 'ninja-forms'); ?></option> 
  133. <option value="_custom" <?php if($custom != 'no') { echo 'selected';}?>><?php _e('Custom', 'ninja-forms'); ?> -></option> 
  134. <option value="querystring" <?php if($default_value_type == 'querystring') { echo 'selected'; $custom = 'yes';}?>><?php _e('Querystring Variable', 'ninja-forms'); ?> -></option> 
  135. </select> 
  136. </span> 
  137. </div> 
  138. <div class="description description-thin"> 
  139.  
  140. <label for="" id="default_value_label_<?php echo $field_id;?>" style="<?php if($custom == 'no') { echo 'display:none;';}?>"> 
  141. <br /> 
  142. <input type="text" class="widefat code nf-default-value-text" name="ninja_forms_field_<?php echo $field_id;?>[default_value]" id="ninja_forms_field_<?php echo $field_id;?>_default_value" value="<?php echo $default_value;?>" data-field-id="<?php echo $field_id; ?>" /> 
  143. <span class="querystring-error" style="display:none;"><?php _e( 'This keyword is reserved by WordPress. Please try another.', 'ninja-forms' ); ?></span> 
  144. </label> 
  145.  
  146.  
  147. </div> 
  148. <?php 
  149. add_action( 'nf_edit_field_advanced', 'nf_field_text_edit_default_value', 9, 2 ); 
  150.  
  151.  
  152. function nf_field_text_edit_input_mask( $field_id, $data ) { 
  153. $field = ninja_forms_get_field_by_id( $field_id ); 
  154. if ( '_text' != $field['type'] ) 
  155. return false; 
  156.  
  157. $custom = ''; 
  158. // Field Mask  
  159. $mask = isset( $data['mask'] ) ? $data['mask'] : ''; 
  160. $plugin_settings = nf_get_settings(); 
  161. $currency_symbol = $plugin_settings['currency_symbol']; 
  162. $date_format = $plugin_settings['date_format']; 
  163. ?> 
  164. <div class="description description-thin"> 
  165. <span class="field-option"> 
  166. <label for=""> 
  167. <?php _e( 'Input Mask' , 'ninja-forms'); ?> 
  168. </label><br /> 
  169. <select id="mask_<?php echo $field_id;?>" name="" class="widefat ninja-forms-_text-mask"> 
  170. <option value="" <?php if($mask == '') { echo 'selected'; $custom = 'no';}?>><?php _e('None', 'ninja-forms'); ?></option> 
  171. <option value="(999) 999-9999" <?php if($mask == '(999) 999-9999') { echo 'selected'; $custom = 'no';}?>><?php _e('Phone - (555) 555-5555', 'ninja-forms'); ?></option> 
  172. <option value="date" <?php if($mask == 'date') { echo 'selected'; $custom = 'no';}?>><?php _e('Date', 'ninja-forms'); ?> - <?php echo $date_format;?></option> 
  173. <option value="currency" <?php if($mask == 'currency') { echo 'selected'; $custom = 'no';}?>><?php _e('Currency', 'ninja-forms'); ?> - <?php echo $currency_symbol;?></option> 
  174. <option value="_custom" <?php if($custom != 'no') { echo 'selected';}?>><?php _e('Custom', 'ninja-forms'); ?> -></option> 
  175. </select> 
  176.  
  177. </span> 
  178. </div> 
  179. <div class="description description-thin"> 
  180. <span class="field-option"> 
  181. <label for="" id="mask_label_<?php echo $field_id;?>" style="<?php if($custom == 'no') { echo 'display:none;';}?>"> 
  182. <?php _e( 'Custom Mask Definition' , 'ninja-forms'); ?>         <a href="#" name="" class="ninja-forms-mask-help"><?php _e( 'Help', 'ninja-forms' ); ?></a><br /> 
  183. <input type="text" id="ninja_forms_field_<?php echo $field_id;?>_mask" name="ninja_forms_field_<?php echo $field_id;?>[mask]" class="widefat code" value="<?php echo $mask; ?>" /> 
  184. </label> 
  185. </span> 
  186. </div> 
  187. <?php 
  188.  
  189. add_action( 'nf_edit_field_restrictions', 'nf_field_text_edit_input_mask', 10, 2 ); 
  190.  
  191. function ninja_forms_field_text_display( $field_id, $data, $form_id = '' ) { 
  192. global $current_user; 
  193. $field_class = ninja_forms_get_field_class( $field_id, $form_id ); 
  194.  
  195. if ( isset( $data['email'] ) && $data['email'] == 1 ) { 
  196. $field_class .= ' email'; 
  197.  
  198. if(isset($data['default_value'])) { 
  199. $default_value = $data['default_value']; 
  200. }else{ 
  201. $default_value = ''; 
  202.  
  203. if(isset($data['label_pos'])) { 
  204. $label_pos = $data['label_pos']; 
  205. }else{ 
  206. $label_pos = "left"; 
  207.  
  208. if(isset($data['label'])) { 
  209. $label = $data['label']; 
  210. }else{ 
  211. $label = ''; 
  212.  
  213. if( isset( $data['mask'] ) ) { 
  214. $mask = $data['mask']; 
  215. }else{ 
  216. $mask = ''; 
  217. }  
  218.  
  219. if( isset( $data['input_limit'] ) ) { 
  220. $input_limit = $data['input_limit']; 
  221. }else{ 
  222. $input_limit = ''; 
  223.  
  224. if( isset( $data['input_limit_type'] ) ) { 
  225. $input_limit_type = $data['input_limit_type']; 
  226. }else{ 
  227. $input_limit_type = ''; 
  228.  
  229. if( isset( $data['input_limit_msg'] ) ) { 
  230. $input_limit_msg = $data['input_limit_msg']; 
  231. }else{ 
  232. $input_limit_msg = ''; 
  233.  
  234. $autocomplete_off = isset ( $data['autocomplete_off'] ) ? $data['autocomplete_off'] : 0; 
  235.  
  236. if ( 1 == $autocomplete_off ) { 
  237. $autocomplete_off = 'autocomplete="off"'; 
  238. } else { 
  239. $autocomplete_off = ''; 
  240.  
  241. switch( $mask ) { 
  242. case '': 
  243. $mask_class = ''; 
  244. break; 
  245. case 'date': 
  246. $mask_class = 'ninja-forms-date'; 
  247. break; 
  248. case 'currency': 
  249. $mask_class = 'ninja-forms-currency'; 
  250. break; 
  251. default: 
  252. $mask_class = 'ninja-forms-mask'; 
  253. break; 
  254.  
  255. if( isset( $data['datepicker'] ) AND $data['datepicker'] == 1 ) { 
  256. $mask_class = 'ninja-forms-datepicker'; 
  257.  
  258. $disable_input = isset( $data['disable_input'] ) ? $data['disable_input'] : 0; 
  259.  
  260. if ( 1 == $disable_input ) { 
  261. $disabled = 'disabled'; 
  262. } else { 
  263. $disabled = ''; 
  264.  
  265. $placeholder = isset ( $data['placeholder'] ) ? $data['placeholder'] : ''; 
  266.  
  267. ?> 
  268. <input id="ninja_forms_field_<?php echo $field_id;?>" data-mask="<?php echo $mask;?>" data-input-limit="<?php echo $input_limit;?>" data-input-limit-type="<?php echo $input_limit_type;?>" data-input-limit-msg="<?php echo $input_limit_msg;?>" name="ninja_forms_field_<?php echo $field_id;?>" type="text" placeholder="<?php echo $placeholder;?>" class="<?php echo $field_class;?> <?php echo $mask_class;?>" value="<?php echo $default_value;?>" rel="<?php echo $field_id;?>" <?php echo $disabled; ?> <?php echo $autocomplete_off; ?> /> 
  269. <?php 
  270.  
  271.  
  272. function ninja_forms_field_text_pre_process( $field_id, $user_value ) { 
  273. global $ninja_forms_processing; 
  274. $plugin_settings = nf_get_settings(); 
  275. if( isset( $plugin_settings['invalid_email'] ) ) { 
  276. $invalid_email = __( $plugin_settings['invalid_email'], 'ninja-forms' ); 
  277. }else{ 
  278. $invalid_email = __( 'Please enter a valid email address.', 'ninja-forms' ); 
  279. $field_row = $ninja_forms_processing->get_field_settings( $field_id ); 
  280. $data = $field_row['data']; 
  281. if( isset( $data['email'] ) AND $data['email'] == 1 AND $user_value != '' ) { 
  282. if ( ! is_email( $user_value ) ) { 
  283.  
  284. //Check False Positive 
  285. if ( 'inside' == $data['label_pos'] AND ( $data['label'] . " *" ) == $ninja_forms_processing->get_field_value( $field_id ) ) { 
  286. //False Positive 
  287. } else { 
  288. $ninja_forms_processing->add_error('email-' . $field_id, $invalid_email, $field_id); 
  289. $ninja_forms_processing->add_error('email-general', $invalid_email); 
  290.  
  291. if( ( isset( $data['replyto_email'] ) AND $data['replyto_email'] == 1 ) OR ( isset( $data['from_email'] ) AND $data['from_email'] == 1 ) ) { 
  292. $user_value = $ninja_forms_processing->get_field_value( $field_id ); 
  293. $ninja_forms_processing->update_form_setting( 'admin_email_replyto', $user_value ); 
  294.  
  295. if( isset( $data['from_name'] ) AND $data['from_name'] == 1 ) { 
  296. $user_value = $ninja_forms_processing->get_field_value( $field_id ); 
  297. if( $ninja_forms_processing->get_form_setting( 'admin_email_name' ) ) { 
  298. $admin_email_name = $ninja_forms_processing->get_form_setting( 'admin_email_name' ); 
  299. $admin_email_name .= " ".$user_value; 
  300. }else{ 
  301. $admin_email_name = $user_value; 
  302. $ninja_forms_processing->update_form_setting( 'admin_email_name', $admin_email_name ); 
  303.  
  304. /** 
  305. * Edit submission value output function 
  306. * 
  307. * @since 2.7 
  308. * @return void 
  309. */ 
  310. function nf_field_text_edit_sub_value( $field_id, $user_value ) { 
  311. ?> 
  312. <input type="text" name="fields[<?php echo $field_id; ?>]" value="<?php echo $user_value; ?>"> 
  313. <?php 
  314.  
  315. /** 
  316. * Output the value that shows up in the submissions table 
  317. * 
  318. * @since 2.7 
  319. * @return void 
  320. */ 
  321. function nf_field_text_sub_table_value( $field_id, $user_value ) { 
  322. // Cut down our string if it is longer than 140 characters. 
  323. $max_len = apply_filters( 'nf_sub_table_user_value_max_len', 140, $field_id ); 
  324. if ( strlen( $user_value ) > 140 ) 
  325. $user_value = substr( $user_value, 0, 140 ); 
  326.  
  327. echo nl2br( $user_value ); 
.