NF_Fields_PasswordConfirm

Class NF_Fields_PasswordConfirm.

Defined (1)

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

/includes/Fields/PasswordConfirm.php  
  1. class NF_Fields_PasswordConfirm extends NF_Fields_Password 
  2. protected $_name = 'passwordconfirm'; 
  3.  
  4. protected $_type = 'passwordconfirm'; 
  5.  
  6. protected $_nicename = 'Password Confirm'; 
  7.  
  8. protected $_section = ''; 
  9.  
  10. protected $_error_message = ''; 
  11.  
  12. protected $_settings = array( 'confirm_field' ); 
  13.  
  14. public function __construct() 
  15. parent::__construct(); 
  16.  
  17. $this->_nicename = __( 'Password Confirm', 'ninja-forms' ); 
  18.  
  19. $this->_settings[ 'confirm_field' ][ 'value' ] = __( 'password', 'ninja-forms' ); 
  20. $this->_settings[ 'confirm_field' ][ 'field_types' ] = array( 'password' ); 
  21. $this->_settings[ 'confirm_field' ][ 'field_value_format' ] = 'key'; 
  22.  
  23. public function validate( $field, $data ) 
  24. $errors = parent::validate( $field, $data ); 
  25.  
  26. $password_fields = $this->get_password_fields( $data ); 
  27.  
  28. if( ! is_array( $password_fields ) || empty( $password_fields ) ) return $errors; 
  29.  
  30. foreach( $password_fields as $password_field ) { 
  31.  
  32. if( $this->is_matching_values( $field, $password_field ) ) continue; 
  33.  
  34. $errors[] = $this->get_error_message(); 
  35.  
  36. return $errors; 
  37.  
  38. private function get_password_fields( $data ) 
  39. $password_fields = array(); 
  40.  
  41. foreach( $data[ 'fields' ] as $field ) { 
  42.  
  43. if( 'password' != $field[ 'type' ] ) continue; 
  44.  
  45. $password_fields[] = $field; 
  46.  
  47. return $password_fields; 
  48.  
  49. private function is_matching_values( $a, $b ) 
  50. return $a[ 'value' ] === $b[ 'value' ]; 
  51.  
  52. private function get_error_message() 
  53. if( $this->_error_message ) return $this->_error_message; 
  54.  
  55. $error_message = __( 'Passwords do not match', 'ninja-forms' ); 
  56.  
  57. $error_message = apply_filters( 'ninja_forms_password_confirm_mismatch', $error_message ); 
  58.  
  59. return $this->_error_message = $error_message;