Question

I'd like to limit user choices for a date to Mondays only.

I store the date field in a MySQL database, and CakePHP automagically generates a date picker for me on the add/edit forms when I use echo $this->Form->input('date');. But it generates drop down menus for year, month and day. That does not seem like a good way to limit user choices to four or five days a month.

I've looked through the options available for the datetime input field on the CakePHP site, and interval is exactly like what I need, but it only applies to the minutes box on a datetime field, and appears to have no effect on the date field.

Is there a clean CakePHP way to go about this, or do I just generate the list of dates on my own and create a drop-down box with those values?

Thanks!

Was it helpful?

Solution

If you want to have a nice UI use Jquery DatePicker

//Cake view
    echo $this->Form->input('created', array('type'=>'text', 'id'=>'created'));

//Jquery 
    $('#created').datepicker({
         dateFormat : 'yy-mm-dd'
    });   

Otherwise you can restrict the date input

//Year
echo $this->Form->year('purchased-year', 2000, date('Y'));
//Month
echo $this->Form->month('mob');
//Day
echo $this->Form->day('created');

FormHelper::hour(string $fieldName, boolean $format24Hours, array $attributes)
Creates a select element populated with the hours of the day.

FormHelper::minute(string $fieldName, array $attributes)
Creates a select element populated with the minutes of the hour.

FormHelper::meridian(string $fieldName, array $attributes)
Creates a select element populated with ‘am’ and ‘pm’.

http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#creating-date-and-time-inputs

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top