CakePHP Application Form Entry Date

I have the following code in my opinion:

$this->Form->input('born');

This is a date field, and I look to see if it is possible to have a different blank text for each selection window, for example: [Month | v] [Day | v] [Year | v].

Has anyone come across this? Great help is appreciated.

+3
source share
5 answers

You can do something like this:

echo $this->Form->input('born', array( 'label' => 'Date of birth', 
   'dateFormat' => 'DMY', 
   'minYear' => date('Y') - 70,
   'maxYear' => date('Y') - 18 ));

They will be dropdowns, not empty text fields. Here you can find out more about form helpers and vending machines:

http://book.cakephp.org/#!/view/1390/Automagic-Form-Elements

+5
source

I resorted to using jquery to update empty cake date values

Cake:

echo $this->Form->input('born', array( 'label' => 'Date of birth', 
   'dateFormat' => 'DMY', 
   'minYear' => date('Y') - 70,
   'maxYear' => date('Y') - 18,
   'empty' => true
 ));

JQuery

$(function() {
    $('.input.date select[name$="[day]"] option[value=""]').html('-- Day --');
    $('.input.date select[name$="[month]"] option[value=""]').html('-- Month --');
    $('.input.date select[name$="[year]"] option[value=""]').html('-- Year --');
});
+3
source
echo $this->Form->input('born', array( 'label' => 'Date of birth',
                                       'type'=>'date',
                                       'dateFormat'=> 'DMY',
                                       'minYear' => date('Y') - 70,
                                       'maxYear' => date('Y') - 18 ));
+2

, :

echo $this->Form->input('born', array('empty' => true));

, : fooobar.com/questions/1812047/...

, , .

0
source

this works for me (CakePHP 2x)

echo $this->Form->input('born', array( 'label' => 'Date of birth', 
   'dateFormat' => 'DMY', 
   'minYear' => date('Y') - 70,
   'maxYear' => date('Y') - 18,
   'empty' => array(
       'day' => '-- Day --', 'month' => '-- Month --', 'year' => '-- Year --',
   )
));
0
source

All Articles