Commit 4799975f authored by Elias Villiger's avatar Elias Villiger
Browse files

Feature #5064 - Throw user form exception on invalid date.

parent 84fd1a0c
......@@ -187,6 +187,7 @@ const ERROR_MAX_FILE_SIZE_TOO_BIG = 1082;
const ERROR_SMALLER_THAN_MIN = 1083;
const ERROR_LARGER_THAN_MAX = 1084;
const ERROR_INVALID_DECIMAL_FORMAT = 1085;
const ERROR_INVALID_DATE = 1086;
// Subrecord
const ERROR_SUBRECORD_MISSING_COLUMN_ID = 1100;
......
......@@ -319,9 +319,17 @@ class FillStoreForm {
throw new UserFormException("DateTime format not recognized: $placeholder / $value ", ERROR_DATE_TIME_FORMAT_NOT_RECOGNISED);
}
$showTime = $formElement[FE_TYPE] == 'date' ? '0' : '1';
$showTime = $formElement[FE_TYPE] == FE_TYPE_DATE ? '0' : '1';
$value = Support::convertDateTime($value, FORMAT_DATE_INTERNATIONAL, '1', $showTime, $formElement[FE_SHOW_SECONDS]);
if ($formElement[FE_TYPE] !== FE_TYPE_TIME) {
// Validate date (e.g. 2010-02-31)
$dateValue = explode(' ', $value)[0];
$dateParts = explode('-', $dateValue);
if (!checkdate($dateParts[1], $dateParts[2], $dateParts[0]))
throw new UserFormException("$dateValue is not a valid date.", ERROR_INVALID_DATE);
}
return $value;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment