Search code examples
formscakephpform-helpers

cakephp birthday helper customize the default values


I would like the to add "month", "day", "year" as the first choice in the birthday menu helper? Can this be done? I don't see any examples of how to do this? Below is the code I have:

    <?php echo $this->Form->input('date_of_birth', 
        array(
            'type' => 'date',
            'label' => 'Date of Birth:<span>*</span>',
            'dateFormat' => 'MDY',
            'empty' => true,
            'minYear' => date('Y')-130,
            'maxYear' => date('Y'),
            'options' => array('1','2')
            )
        );
    ?>

Thanks, Bart


Solution

  • Here you go, the empty option accepts an array where you can specify the empty value for the individual fields using the keys month, year, day, hour, minute and meridian:

    echo $this->Form->input('date_of_birth', 
        array(
            'type' => 'date',
            'label' => 'Date of Birth:<span>*</span>',
            'dateFormat' => 'MDY',
            'empty' => array(
                'month' => 'Month',
                'day'   => 'Day',
                'year'  => 'Year'
            ),
            'minYear' => date('Y')-130,
            'maxYear' => date('Y'),
            'options' => array('1','2')
        )
    );