Hi this is a part of my PictureForm.php
$picture = new File("picture", array(
"class" => "form-control"
));
/*$picture->addValidator(new PresenceOf(array(
"message" => "'File' field can't be empty !"
)));*/
$this->add($picture);
and there is the part of my PictureController.php
public function addAction()
{
$form = new PictureForm();
if($this->request->isPost())
{
if($form->isValid($this->request->getPost()) != false)
{
if($this->request->hasFiles())
{
foreach($this->request->getUploadedFiles() as $file)
{
$picture = new Picture();
$picture->assign(array(
"src" => "img/photos/".$file->getName(),
"alt" => $file->getName(),
));
if($picture->save() and $file->moveTo("img/photos/".$file->getName()))
{
$this->flashSession->success("Great ! You're picture was successfully uploaded !");
$response = new Response();
return $response->redirect(array(
"for" => "adminIndex",
"controller" => "admin"
));
}
}
}
else
{
$this->flash->error("'File' field can't be empty !");
}
}
else
{
foreach($form->getMessages() as $message)
{
$this->flash->error($message);
}
}
}
$this->view->setVar("form", $form);
$this->view->pick("admin/picture/add");
}
As you can see i've commented the validator and i'm validating the file field manually in the controller . I'm wondering if the solution with the validator which ain't working in my case is a better solution or not ?