1
votes

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

4

4 Answers

1
votes

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.

0
votes

I believe you can only set a default date on the date fields.

echo $this->Form->input('close_time', array('type' => 'time', 'selected' => '13:30:00'));

Cookbook entry

0
votes

For the benefit of anyone Googling to find the answer to this question 1+ years after it was asked, we can now simply do the following to set default placeholder (temporary) values in CakePHP forms that are easily replaced when clicked:

<?php echo $this->Form->input('Email', array(
'placeholder'=>'Enter Your Email Here'
)); ?>

I like to include 'label' => false as well to make the forms really minimalist.

0
votes

http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-select-checkbox-and-radio-inputs

echo $this->Form->dateTime('Contact.date', 'DMY', '12',
    array(
        'empty' => array(
            'day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR',
            'hour' => 'HOUR', 'minute' => 'MINUTE', 'meridian' => false
        )
    )
);