Form checking: Craft allows to enter invalid dates #10078
-
Describe the issue When editing a content entry it is possible to enter an invalid date, Craft will accept saving the entry without reporting that the entered data is invalid. To reproduce On any content entry that accept a date (e.g. Alumni). Test 1:
Test 2:
Expected behavior In both cases the form submission should fail indicating that "31/31/2021" (or "abcd") is not a valid dates. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Thanks for the report!
This is awkward but actually working as expected. Assuming your user account’s formatting locale is set to “English (United Kingdom)”, Craft knows the submitted date will be in the format DateTime::createFromFormat('!d/m/Y e', '31/31/2021 UTC') That would return a DateTime object with a value of
Yeah that’s a legitimate bug. Unfortunately the way we handle user-submitted date values, we can’t tell the difference between an invalid date and an empty date, so all invalid values are just considered empty. Good news is, we’ll have both of these fixed in Craft 4, as we are moving all date/time inputs to the native browser |
Beta Was this translation helpful? Give feedback.
Thanks for the report!
This is awkward but actually working as expected. Assuming your user account’s formatting locale is set to “English (United Kingdom)”, Craft knows the submitted date will be in the format
d/m/Y e
. And if you were to run the following PHP code:That would return a DateTime object with a value of
2023-07-31 00:00:00.000000
. The way it sees it, the 13th month of 2021 is January 2022; the 14th month of 2021 is February 2022; etc… and the 31st month of 2021 is July 2023. Does that make sense?