/deprecated/includes/display/processing/req-fields-pre-process.php

  1. <?php if ( ! defined( 'ABSPATH' ) ) exit; 
  2.  
  3. function ninja_forms_req_fields_process() { 
  4. global $ninja_forms_processing, $ninja_forms_fields; 
  5.  
  6. $all_fields = $ninja_forms_processing->get_all_fields(); 
  7.  
  8. if( is_array( $all_fields ) AND !empty( $all_fields ) ) { 
  9. foreach($all_fields as $field_id => $user_value) { 
  10.  
  11. $field_row = $ninja_forms_processing->get_field_settings( $field_id ); 
  12.  
  13. if ( !$field_row ) { 
  14. $field_row = ninja_forms_get_field_by_id( $field_id ); 
  15.  
  16. $field_type = $field_row['type']; 
  17.  
  18. if ( isset ( $ninja_forms_fields[$field_type] ) ) { 
  19.  
  20. if( isset( $field_row['data'] ) ) { 
  21. $field_data = $field_row['data']; 
  22. }else{ 
  23. $field_data = ''; 
  24.  
  25. if( isset( $field_data['req'] ) ) { 
  26. $req = $field_data['req']; 
  27. }else{ 
  28. $req = ''; 
  29.  
  30. if( isset( $field_data['label_pos'] ) ) { 
  31. $label_pos = $field_data['label_pos']; 
  32. }else{ 
  33. $label_pos = ''; 
  34. // Get the required field symbol. 
  35. $settings = nf_get_settings(); 
  36. if ( isset ( $settings['req_field_symbol'] ) ) { 
  37. $req_symbol = $settings['req_field_symbol']; 
  38. } else { 
  39. $req_symbol = '*'; 
  40.  
  41. if ( isset ( $field_data['req'] ) and $field_data['req'] == 1 and $label_pos == 'inside' ) { 
  42. $field_data['label'] .= ' '.$req_symbol; 
  43.  
  44. if( isset( $field_data['label'] ) ) { 
  45. $label = $field_data['label']; 
  46. }else{ 
  47. $label = ''; 
  48.  
  49. $label = strip_tags( $label ); 
  50.  
  51. $reg_type = $ninja_forms_fields[$field_type]; 
  52. $req_validation = $reg_type['req_validation']; 
  53.  
  54. $plugin_settings = nf_get_settings(); 
  55. if ( isset ( $plugin_settings['req_field_error'] ) ) { 
  56. $req_field_error = __( $plugin_settings['req_field_error'], 'ninja-forms' ); 
  57. } else { 
  58. $req_field_error = __( 'This is a required field.', 'ninja-forms' ); 
  59.  
  60. if( isset( $plugin_settings['req_error_label'] ) ) { 
  61. $req_error_label = __( $plugin_settings['req_error_label'], 'ninja-forms' ); 
  62. }else{ 
  63. $req_error_label = __( 'Please check required fields.', 'ninja-forms' ); 
  64.  
  65. if( $req == 1 AND $user_value !== false ) { 
  66.  
  67. if($req_validation != '') { 
  68. $arguments['field_id'] = $field_id; 
  69. $arguments['user_value'] = $user_value; 
  70. $req = call_user_func_array($req_validation, $arguments); 
  71. if(!$req) { 
  72. $ninja_forms_processing->add_error('required-'.$field_id, $req_field_error, $field_id); 
  73. $ninja_forms_processing->add_error('required-general', $req_error_label, 'general'); 
  74. }else{ 
  75. if($label_pos == 'inside') { 
  76. if( $user_value == $label OR ( empty( $user_value ) && $user_value !== "0" ) ) { 
  77. $ninja_forms_processing->add_error('required-'.$field_id, $req_field_error, $field_id); 
  78. $ninja_forms_processing->add_error('required-general', $req_error_label, 'general'); 
  79. }else{ 
  80. if( $user_value === '' ) { 
  81. $ninja_forms_processing->add_error('required-'.$field_id, $req_field_error, $field_id); 
  82. $ninja_forms_processing->add_error('required-general', $req_error_label, 'general'); 
  83.  
  84. add_action( 'ninja_forms_pre_process', 'ninja_forms_req_fields_process', 13); 
.