I have a strange pb with my form for uploading image files that I dont understand. I try to upload images and create thumbnails from the uploaded files.
for example I have this definition for my form :
$builder->add('image', 'file'); (in my ImageType) with a good Class/object Image theres no pb to render the form
in my Controller I have :
- Code: Select all
...some code
$image= new Image();
$formImage= $this->createForm(new ImageType(), $image);
if ($request->getMethod() == 'POST' ) {
$formImage->bindRequest($request);
$image = $formImage['image']->getData();
$response = $this->forward('PkTestBundle:CreateImage:index', array('img' => $image));
return $response;
..some code
Everything works fine, it uploads files and creates the thumbnails but if I try to check if the form is valid :
- Code: Select all
...some code
if ($request->getMethod() == 'POST' ) {
$formImage->bindRequest($request);
if ($formImage->isValid()){ <-line added
$image = $formImage['image']->getData();
$response = $this->forward('PkTestBundle:CreateImage:index', array('img' => $image));
return $response;
}
else throw $this->createNotFoundException('form invalid); <-line added
..some code
It doesn't work! I have the Exception message 'form invalid'. I retired the line 'if ($formImage->isValid())'. its not normal that in one case it works and in the other case it doesn't while its exactly the same form.
Can someone explain me why? I miss something?
thanks
