My form validation doesn't appear to be working. If I add an image, and submit the form, the validator complains that an image hasn't been uploaded. But, when I var_dump() the $_FILES variable, the file is there. And $this->request->getUploadedFiles() shows there's a file.
It's the validator that isn't working I believe.
Here is the code within the controller that validates the form ...
$form = new CreateSnapForm();
/*
* Check form inputs
*/
if(!$form->isValid($this->request->getPost()))
{
$this->session->set('old_data', $_POST);
$this->flashSession->error($form->getMessages()[0]);
return $this->response->redirect('/');
}
Here is the validator
/*
* Image upload
*/
$image = new File('image');
$image->addValidator(new FileValidator([
'maxSize' => '2M',
'messageSize' => 'Your image is too big. Max file size: 2MB',
'allowedTypes' => ['image/jpeg', 'image/png'],
'messageType' => 'Your image must be a JPEG or PNG file',
'messageEmpty' => 'No image uploaded'
]));
Any ideas what's going wrong?