A note on $form->dateTime(‘field_name’) generating offset warning in CakePHP

This is a note on $form->dateTime(‘field_name’) generating offset warning i.e. “Notice (8): Undefined offset: 1 [CORE/cake/libs/view/helpers/form.php, line 1836..“. If your “date” form field in a view is generating a similar warning you may need to look into the following scenario.

Prior to Cake 1.3 the $form->dateTime() accepted the third argument ‘timeFormat’ as ‘NONE’ in addition to ’12’ or ’24’. If no time was involved you would pass ‘NONE’. For example for a ‘date only’ field one would have done:

echo $form->dateTime(‘User.date_of_birth’,’MDY’, ‘NONE’, null, $attributes=array())

However, as of Cake 1.3 the value “NONE” for third argument is no more valid and “dateTime” function now accepts 12, 24 or null. So if your form field is a kind of MDY format (where no time is involved) you would want to replace the third argument i.e. ‘NONE’ with null.

Leave a Reply

Your email address will not be published. Required fields are marked *