Search code examples
formscakephpcakephp-1.3placeholderselect-menu

How to set place holder copy in date select menu in CakePHP


I am using CakePHP 1.3 to create a select menu for date of birth (as below). I can set the default starting values as either blank or a selected date, but ideally I would like to have DD-MM-YYYY as the starting displayed values:

echo $form->input('dob', 
    array(
    'before' => '', 
    'between' => '', 
    'after' => '', 
    'label' => false, 
    'divider' => false, 
    'monthNames' => false, 
    'selected' => false, 
    'empty' => true, 
    'dateFormat' => 'DMY', 
    'minYear' => date('Y') - 70,
    'maxYear' => date('Y') - 16,
    'error' => array('wrap' => 'div', 'class' => 'error-copy')
    ));

What I get:

Date of birth select menus

What I would like:

Placeholder DD MM YYYY copy

Thank you


Solution

  • I believe if you want to do this you will have to make your own date fields and not use the FormHelper since you can only set a default date to it, what you want involves adding an element to the fields.

    You could also try JQuery's datepicker out, it's what I use in my project, and since it's a text field you can just set whatever you want as a placeholder.