'/[0-9]{2}[\-\/\.][0-9]{2}[\-\/\.][0-9]{2,4}$/i', 'headline' => VALID_NOT_EMPTY, 'detail' => VALID_NOT_EMPTY ); // Extra form validation, since VALID_NOT_EMPTY does not work on // these fields. function validates() { $event = $this->data['Event']; if(empty($event['date_hour']) || empty($event['date_meridian']) || empty($event['date_meridian'])) $this->invalidate('date'); $errors = $this->invalidFields(); return count($errors) == 0; } /* * The validation above is optional, just to give you an idea * of how to validate these fields. */ function afterFind($results) { // Create a dateOnly pseudofield using date field. foreach ($results as $key => $val) { if (isset($val['Event']['date'])) $results[$key]['Event']['dateOnly'] = date('m-d-Y',strtotime($val['Event']['date'])); } return $results; } function beforeSave() { // Convert 12 hour to 24 hour if($this->data['Event']['date_meridian'] == 'pm') $hour = $this->data['Event']['date_hour'] + 12; else $hour = $this->data['Event']['date_hour']; // Get month day and year from date string $timestamp = strtotime(str_replace('-','/',$this->data['Event']['dateOnly'])); $month = date('m',$timestamp); $day = date('d',$timestamp); $year = date('Y',$timestamp); $this->data['Event']['date'] = date('Y-m-d H:i:s', mktime( $hour, $this->data['Event']['date_min'], null, $month, $day, $year)); return true; } ?>