I want to validate date from user input so I made this function:
private function validateData(string $date, string $returnUrl)
{
$validator = new Validation();
$validator->add($this->request->getPost($date), new DateValidator([
'format' => 'Y-m-d',
]));
$messages = $validator->validate($this);
if (count($messages)) {
foreach ($messages as $message) {
$this->flashSession->error($message->getMessage());
}
return $this->response->redirect($returnUrl)->send();
}
}
Now everytime I edit a post an error message get's thrown: "Field 2015-02-10 is not a valid date"
So I thought maybe it want's the actual name of the field. So I tried that but then I get: "Field publicationDate is not a valid date".
Can anyone explain to me why this is happening and why the validation isn't being stopped if the validation encounters an unsupported date format?