NF_Fields_Date

Class NF_Fields_Date.

Defined (1)

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

/includes/Fields/Date.php  
  1. class NF_Fields_Date extends NF_Fields_Textbox 
  2. protected $_name = 'date'; 
  3.  
  4. protected $_nicename = 'Date'; 
  5.  
  6. protected $_section = 'common'; 
  7.  
  8. protected $_icon = 'calendar'; 
  9.  
  10. protected $_type = 'date'; 
  11.  
  12. protected $_templates = 'date'; 
  13.  
  14. protected $_test_value = '12/12/2022'; 
  15.  
  16. protected $_settings = array( 'date_default', 'date_format' ); 
  17.  
  18. protected $_settings_exclude = array( 'default', 'placeholder', 'input_limit_set', 'disable_input' ); 
  19.  
  20. public function __construct() 
  21. parent::__construct(); 
  22.  
  23. $this->_nicename = __( 'Date', 'ninja-forms' ); 
  24.  
  25. public function process( $field, $data ) 
  26.  
  27. foreach( $data[ 'fields' ] as $key => $field ) { 
  28.  
  29. if( 'date' != $field[ 'type' ] ) continue; 
  30. if( ! isset( $field[ 'date_format' ] ) || ! $field[ 'date_format' ] ) continue; 
  31.  
  32. $format = $this->get_format( $field[ 'date_format' ] ); 
  33. $data[ 'fields' ][ $key ][ 'value' ] = date( $format, strtotime( $field[ 'value' ] ) ); 
  34.  
  35. return $data; 
  36.  
  37. private function get_format( $format ) 
  38. $lookup = array( 
  39. 'DD/MM/YYYY' => __( 'm/d/Y', 'ninja-forms' ),  
  40. 'DD-MM-YYYY' => __( 'd-m-Y', 'ninja-forms' ),  
  41. 'MM/DD/YYYY' => __( 'm/d/Y', 'ninja-forms' ),  
  42. 'MM-DD-YYYY' => __( 'm-d-Y', 'ninja-forms' ),  
  43. 'YYYY-MM-DD' => __( 'Y-m-d', 'ninja-forms' ),  
  44. 'YYYY/MM/DD' => __( 'Y/m/d', 'ninja-forms' ),  
  45. 'dddd, MMMM D YYYY' => __( 'l, F d Y', 'ninja-forms' ) 
  46. ); 
  47.  
  48. return ( isset( $lookup[ $format ] ) ) ? $lookup[ $format ] : $format; 
  49.