We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
isDate validator is returning true for some dates that are not valid.
core/components/formit/src/FormIt/Validator.php, line #658 public function isDate($key, $value, $format = '%m/%d/%Y') { /* allow empty isDate, :required should be used to prevent blank field */ if (empty($value)) { return true; } $ts = strtotime($value); if ($ts === false) { return $this->_getErrorMessage($key,'vTextIsDate','formit.not_date',array( 'format' => $format, 'field' => $key, 'value' => $value, )); } if (!empty($format)) { $this->fields[$key] = strftime($format,$ts); } return true; }
strtotime is not a sufficient way to validate a date string because it is "fixing" problems it should not.
Simple snippet to test if there is a February 29th in a given year:
<?php # Name: testDate snippet # Usage: [[!testDate? &input=`2020-02-29`]] if(strtotime($input)) { return date('Y-m-d',strtotime($input)); } else { return "false"; }
Validation of dates within the bounderies of february is not trustworthy.
Dates within the scope of february should be handled in a proper way.
The php function checkdate() might be helpful here.
Docs: https://www.php.net/manual/en/function.checkdate.php
MODX 2.8.1, Formit 4.2.6 , PHP 7.4.18, Apache Webserver Running on Ubuntu Linux.
The text was updated successfully, but these errors were encountered:
Something like this shold do the trick:
function isValidDate(string $date, string $format = 'Y-m-d'){ // php $dateObj = DateTime::createFromFormat($format, $date); return $dateObj && $dateObj->format($format) == $date; }
Sorry, something went wrong.
No branches or pull requests
Bug report
isDate validator is returning true for some dates that are not valid.
Summary
strtotime is not a sufficient way to validate a date string because it is "fixing" problems it should not.
Step to reproduce
Simple snippet to test if there is a February 29th in a given year:
2020 was a leap year.
2021 was NOT a leap year
Every day <= 31 returns for february a day in the next month
It does the right thing if it encounters impossible dates:
Observed behavior
Validation of dates within the bounderies of february is not trustworthy.
Expected behavior
Dates within the scope of february should be handled in a proper way.
The php function checkdate() might be helpful here.
Docs: https://www.php.net/manual/en/function.checkdate.php
Environment
MODX 2.8.1, Formit 4.2.6 , PHP 7.4.18, Apache Webserver Running on Ubuntu Linux.
The text was updated successfully, but these errors were encountered: