Hi,
I was just looking for this too. I came up with this solution using
the beforeValidate().
1.) At the view, split the datetime into two fields, date and time :
<?= $form->input('date', array('type' => 'date'));?>
<?= $form->input('time', array('type' => 'time'));?>
2.) Then inside your Model, create the beforeValidate() function:
function beforeValidate(){
// In my case, time is optional so I have extra code to set it to
00:00:00 if not provided.
$date = implode('-', $this->data['Model']['date']);
$time = implode(':', $this->data['Model']['time']);
// Combine the date and time to make the mysql timestamp format:
$this->data['Model']['datetime'] = $date . ' ' . $time;
}
3. And just validate the date and time normally:
var $validate = array(
'date' => array('rule' => array('date', 'mdy'), 'required' => false,
'message' => 'Please select a valid date.'),
'time' => array('rule' => 'time', 'required' => false, 'message' =>
'Please select a valid time.')
)
So basically we don't need a new datetime validation, we just need to
validate each field separately.
- Kien
On Aug 6, 5:20 pm, PaulMan <[EMAIL PROTECTED]> wrote:
> Hello, Thanks Chris,
> Since i found the Date and Time validation methods, i was "hopping" to
> find also a DateTime validation...
> I'll go to a Custom Validation Method, if any one already extended the
> Validation class with this please post.
> Thanks.
>
>
>
> > My, my, so many polite people on the mailing list these days.
>
> > While there is a date validation method, I don't see any date + time
> > validation method in this section:
>
> >http://book.cakephp.org/view/125/data-validation
>
> > So, my guess would be that you will have to write your own custom
> > validation method if you want to validate a dateTime string. I'm
> > thinking you're talking about something like this:
>
> > 2008-08-06 12:45PM
>
> > The example doesn't matter really, as it's just a little bit of work
> > with regular expressions to make your own validation method.
> > I'm sure a little bit of work with google will find the regular
> > expression you need.
>
> > Try this tool to create the regex:
>
> >http://www.txt2re.com/
>
> > --
> > Chris Hartjes
> > Motto for 2008: "Moving from herding elephants to handling snakes..."
> > @TheKeyBoard:http://www.littlehart.net/atthekeyboard
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---