开发者

CakePHP Date Validation from timestamp field

I'm using CakePHP 1.3.10 with a MySQL database.

The field event_date has the type "timestamp" in MySQL. The great automagic form element helper gives me a nice dropdown menu.

echo $form->input('event_date'); 

The problem is, I noted that users could still input invalid, non-existing dates, like the 31st of June.

Okay, I thought ... let's crack out the validation rules. The problem is, the input form puts data in an array([month] => '31', [day] => '06', [year] => '2011', '[hour]' ... et cetera.

The default validation rules only seem to work on strings ... how can I validate in this case? I'd like to stay within the CakePHP framework, I'm still k开发者_StackOverflow社区inda new. I'm just looking for an additional rule to add to my already set 'notempty' rule:

 'event_date' => array(
        'rule' => 'notEmpty',
        'message' => 'Please enter a valid date for this event'
    ),

I've looked around in the CakePHP documentation, but can't find anything useful. Seems a bit weird that I'd have to go to a lot of trouble to validate the input of an automagically generated form field.


check

http://book.cakephp.org/view/1159/date

for date validation rules. this should work.

of course this will not check if June has 31 days on the fly, but should provide an error message, when this date does not exist.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜