#6079: Form Helper - DateTime: Providing a YmD for short month
    Reporter:  justinvh        |          Type:  Enhancement
      Status:  new             |      Priority:  Medium     
   Milestone:  1.2.x.x         |     Component:  Helpers    
     Version:  1.2 Final       |      Severity:  Trivial    
    Keywords:  DateTime, Form  |   Php_version:  PHP 5      
Cake_version:      |  
 == Situation ==
 As of Stable DateTime provides a way to auto-generate all forms
 YYYY-MM-DD and YYYY-LONGMONTH-DD, however there is no way to produce a
 short-month form without modifying the form helper.
 == Possible Implementation ==
 '''In the form helper:'''[[BR]]
 Provided another case of 'shortMonth' to generationOptions:
 function __generateOptions($name, $options = array()) {
     case 'shortMonth':
     if ($options['monthNames']) {
       $data['01'] = __('Jan', true);
       $data['02'] = __('Feb', true);
       $data['03'] = __('Mar', true);
       $data['04'] = __('Apr', true);
       $data['05'] = __('May', true);
       $data['06'] = __('Jun', true);
       $data['07'] = __('Jul', true);
       $data['08'] = __('Aug', true);
       $data['09'] = __('Sep', true);
       $data['10'] = __('Oct', true);
       $data['11'] = __('Nov', true);
       $data['12'] = __('Dec', true);
     } else {
       for ($m = 1; $m <= 12; $m++) {
         $data[sprintf("%02s", $m)] = strftime("%m", mktime(1, 1, 1, $m, 1,

 In the function month, provide an optional argument $useShort and a
 conditional for generating the month list:
 function month($fieldName, $selected = null, $attributes = array(),
 $showEmpty = true, $useShort = false) {
     return $this->select(
         $fieldName . ".month",
         $this->__generateOptions((($useShort == true) ? 'shortMonth' :
 'month'), array('monthNames' => $monthNames)),
         $selected, $attributes, $showEmpty

 And finally, in the function DateTime, add another case to the preg_split
 on dateFormat:
 function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12',
 $selected = null, $attributes = array(), $showEmpty = true) {
     case 'm':
         $selectMonthAttr['monthNames'] = $monthNames;
         $selects[] = $this->month($fieldName, $month, $selectMonthAttr,
 $showEmpty, true);
 == Use ==
 echo $form->input('Date.date', array('dateFormat' => 'mDY'))
 == Why Does Cake Need This? ==
 A good situation was my current project that has constraints on document
 size; according to the specifications, I had to fit a date and time
 selection onto a single line. I had to set a width for the select element
 to fit everything on one line (645px document width). The select box for
 the month drop-down looked horrible. It was a perfect size for a short-
 date syntax, but nothing such existed.

Ticket URL: <https://trac.cakephp.org/ticket/6079>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design 
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. 
Our primary goal is to provide a structured framework that enables PHP users at 
all levels to rapidly develop robust web applications, without any loss to 
You received this message because you are subscribed to the Google Groups 
"tickets cakephp" group.
To post to this group, send email to tickets-cakephp@googlegroups.com
To unsubscribe from this group, send email to 
For more options, visit this group at 

  • [CakePHP : The Rapid Dev... CakePHP : The Rapid Development Framework for PHP

Reply via email to