strange form validation pb

New topics about Symfony 2 should go here

Moderators: dcobalt, tiagojsag

strange form validation pb

Postby skandaboy » Fri Jun 15, 2012 2:28 pm

Hello,

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
skandaboy
Junior Member
 
Posts: 23
Joined: Mon Aug 08, 2011 2:17 pm

Re: strange form validation pb

Postby skandaboy » Tue Jun 19, 2012 7:32 pm

someone has an idea? :?:
skandaboy
Junior Member
 
Posts: 23
Joined: Mon Aug 08, 2011 2:17 pm

Re: strange form validation pb

Postby dreipunktnull » Tue Jun 19, 2012 10:03 pm

Hard to tell without seeing the image class' validation constraints.
User avatar
dreipunktnull
Faithful Member
 
Posts: 1244
Joined: Fri Jun 17, 2011 10:03 am
Location: Germany

Re: strange form validation pb

Postby skandaboy » Thu Jun 21, 2012 4:52 pm

well actually I changed the form declaration to this :
$formImage = $this->createFormBuilder()->add('image', 'file')->getForm();

and the controller :
Code: Select all
...
if ($request->getMethod() == 'POST') {
                    $formImage->bindRequest($request); 
                    if ($formImage->isValid()) {
                    $image = $formImage['image']->getData();
                    $response = $this->forward('PkTestBundle:CreateImage:index', array('img' => $image));
                    return $response;
                    }
                    else throw $this->createNotFoundException ('Formulaire invalid');
...

and still I have the exception message when I submit the form. So I dont get what happen
skandaboy
Junior Member
 
Posts: 23
Joined: Mon Aug 08, 2011 2:17 pm


Return to General Symfony 2 discussion

Who is online

Users browsing this forum: No registered users and 9 guests