selectdate - date selector YYYY MM DD

selectDate

Date selection input type with separate selects for year, month and day.

  • a hidden input field is automatically attached for this element to hold the actual values of the selects. This way you can still use the standard 'date' validation type as you would do on a text input
  • You can use the layout setting to change the order of the separate selects (eg. if your visitors prefer M D Y instead of the ISO standard Y M D)
  • Use the format setting to change the resulting date format of the concatenation: by default, selectDate returns dates in Y-M-D format.
  • Use padding, null, yearfrom, yearuntil, months to customize your date selector!

<?php

$config 
= Array(

  
'selectdate' => Array(
    
'type'           => 'selectDate',
    
'displayname'    => 'Your birthdate is...'',

    '
layout' => '%%%D',
      // we use % here to avoid problems with Y, M and D letters
      // in the layout string.
      // eg. if you'
d like to use a select like
      
//   Year: [    ] Month: [    ] Day: [    ]
      // you should specify:
      //   $layout = 'Year: %Y Month: %M Day: %D'
  
    
'format' => '%Y-%M-%D',
      
// format is used to specify the 'compiled' result of
      // the selects returned by getValue
  
    
'padding' => true,
      
// store month and day with two digits 
      // (01..12, 01..31 )
      // (affects only the 'results' not the option texts)
  
    
'null' => Array( '' => '' ),
      
// if $null is not false, but an array, it is used
      // for enabling empty dates. You may set it like:
      // Array( '' => '-- choose --' ) and combine
      // the element with a date validation.
  
    
'yearfrom' => false
    
// if ===false, will be set to current year in constructor
  
    
'yearuntil' => 1900,  
    
// if ===false, will be set to current year in constructor
  
    // if $yearfrom is larger than $yearuntil, you'll get a 
    // decrementing list of years, which is more natural to the users
    
    
'months' => Array( 
      
=> MONTH_01,  => MONTH_02,  => MONTH_03,  => MONTH_04
      
=> MONTH_05,  => MONTH_06,  => MONTH_07,  => MONTH_08
      
=> MONTH_0910 => MONTH_1011 => MONTH_1112 => MONTH_12
    
),
    
// these default month names are defined in messages_en.php

    
'onbeforechange' => 'JS_code_here_with_trailing_semicolon();',
    
'onafterchange'  => 'JS_code_here_with_trailing_semicolon();',
    
// these hooks allow you to run your own function(s)
    // whenever the selects change

    
'value'          => 'default value here',
    
'html'           => 'class="inputfieldstyle"',
    
'help'           => 'validation failed for this element',
    
'rowlayout'      => '...%element% %prefix% %postfix% etc...',
    
'prefix'         => 'string to display before element',
    
'postfix'        => 'string to display after element',
    
'readonly'       => 0,
    
'display'        => 0,
    
'htmlid'         => 'name1',
);

?>


Live examples:

Validators to use together with this element:

form validation for developers!

clonefish is a proven, mature form generator class that helps PHP developers to create, validate and process secure, flexible and easy-to-maintain forms
learn more
Bookmark and Share