diff --git a/forms/DateField.php b/forms/DateField.php index e230db50f..6495732d3 100755 --- a/forms/DateField.php +++ b/forms/DateField.php @@ -301,14 +301,16 @@ JS; */ function validateArrayValue($val) { if(!is_array($val)) return false; - + + // Validate against Zend_Date, + // but check for empty array keys (they're included in standard form submissions) return ( array_key_exists('year', $val) - && Zend_Date::isDate($val['year'], 'yyyy', $this->locale) + && (!$val['year'] || Zend_Date::isDate($val['year'], 'yyyy', $this->locale)) && array_key_exists('month', $val) - && Zend_Date::isDate($val['month'], 'MM', $this->locale) + && (!$val['month'] || Zend_Date::isDate($val['month'], 'MM', $this->locale)) && array_key_exists('day', $val) - && Zend_Date::isDate($val['day'], 'dd', $this->locale) + && (!$val['day'] || Zend_Date::isDate($val['day'], 'dd', $this->locale)) ); } @@ -330,7 +332,10 @@ JS; if(!$valid) { $validator->validationError( $this->name, - _t('DateField.VALIDDATEFORMAT2', sprintf("Please enter a valid date format (%s).", $this->getConfig('dateformat'))), + sprintf( + _t('DateField.VALIDDATEFORMAT2', "Please enter a valid date format (%s)."), + $this->getConfig('dateformat') + ), "validation", false ); diff --git a/forms/DatetimeField.php b/forms/DatetimeField.php index ce8523005..b4cb4d053 100644 --- a/forms/DatetimeField.php +++ b/forms/DatetimeField.php @@ -150,7 +150,7 @@ class DatetimeField extends FormField { function validate($validator) { $dateValid = $this->dateField->validate($validator); $timeValid = $this->timeField->validate($validator); - + return ($dateValid && $timeValid); } diff --git a/forms/TimeField.php b/forms/TimeField.php index 313392920..053ecfe78 100755 --- a/forms/TimeField.php +++ b/forms/TimeField.php @@ -146,7 +146,10 @@ class TimeField extends TextField { if(!Zend_Date::isDate($this->value, $this->getConfig('timeformat'), $this->locale)) { $validator->validationError( $this->name, - _t('TimeField.VALIDATEFORMAT', sprintf("Please enter a valid time format (%s)", $this->getConfig('timeformat'))), + sprintf( + _t('TimeField.VALIDATEFORMAT', "Please enter a valid time format (%s)"), + $this->getConfig('timeformat') + ), "validation", false ); diff --git a/lang/en_US.php b/lang/en_US.php index b73dc61ab..594bd425c 100644 --- a/lang/en_US.php +++ b/lang/en_US.php @@ -152,7 +152,7 @@ $lang['en_US']['DateField']['NOTSET'] = 'not set'; $lang['en_US']['DateField']['TODAY'] = 'today'; $lang['en_US']['DateField']['VALIDATIONJS'] = 'Please enter a valid date format (DD/MM/YYYY).'; $lang['en_US']['DateField']['VALIDDATEFORMAT'] = 'Please enter a valid time format.'; -$lang['en_US']['DateField']['VALIDDATEFORMAT2'] = 'Please enter a valid time format (%s)'; +$lang['en_US']['DateField']['VALIDDATEFORMAT2'] = 'Please enter a valid date format (%s)'; $lang['en_US']['DateField']['VALIDDATEMAXDATE'] = 'Your date has to be older or matching the maximum allowed date (%s)'; $lang['en_US']['DateField']['VALIDDATEMINDATE'] = 'Your date has to be newer or matching the minimum allowed date (%s)'; $lang['en_US']['DropdownField']['CHOOSE'] = array( diff --git a/tests/forms/DateFieldTest.php b/tests/forms/DateFieldTest.php index 20705a5bf..cec80df41 100644 --- a/tests/forms/DateFieldTest.php +++ b/tests/forms/DateFieldTest.php @@ -125,6 +125,9 @@ class DateFieldTest extends SapphireTest { $f->setValue(array()); $this->assertTrue($f->validate(new RequiredFields()), 'Empty array values are validating TRUE'); + $f->setValue(array('day' => null, 'month' => null, 'year' => null)); + $this->assertTrue($f->validate(new RequiredFields()), 'Empty array values with keys are validating TRUE'); + // TODO Fix array validation // $f = new DateField('Date', 'Date', array('day' => 9999, 'month' => 9999, 'year' => 9999)); // $this->assertFalse($f->validate(new RequiredFields()));