From e527f0bb28d40cdae66157cd3683ecb3d380d33c Mon Sep 17 00:00:00 2001 From: Charl Joseph Mert Date: Mon, 26 Oct 2009 15:18:31 +0200 Subject: [PATCH] Date format validation attempts to force the user to enter a date in the correct format on a field where the user did not enter a date on a non-Required field. Jira:KTS-4434 --- plugins/ktcore/KTValidators.php | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/plugins/ktcore/KTValidators.php b/plugins/ktcore/KTValidators.php index de800e3..b052610 100644 --- a/plugins/ktcore/KTValidators.php +++ b/plugins/ktcore/KTValidators.php @@ -588,24 +588,19 @@ class KTDateValidator extends KTValidator { function validate($data) { $results = array(); $errors = array(); - - // very simple if we're required and not present, fail - // otherwise, its ok. - $pMetaKey = array_keys($data); - $fieldId = str_replace('metadata_', '', $pMetaKey); - $oField = new DocumentField(); - $oField->load($fieldId); - - if (!$oField->getIsMandatory()) { - return; - } - + $val = KTUtil::arrayGet($data, $this->sInputVariable); - + if ($this->bTrim) { $val = trim($val); } + // very simple if we're required and not present, fail + // otherwise, its ok. + if (empty($val) || $val == '') { + return; + } + if (preg_match ("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/", $val, $parts)) { //check weather the date is valid of not -- libgit2 0.21.4