I am trying to customize a file upload form under Symfony2 with a downloadable extension (stof / doctrine)
here are my entities
club
<?php ... class Club { ... private $logo; ... }
file
<?php ... use Gedmo\Mapping\Annotation as Gedmo; use Doctrine\ORM\Mapping as ORM; ... class File { ... private $name; ...
my clubType form type
$builder->add('logo', new FileType())
Filetype
$builder->add('name', 'file', array( 'required' => false, ))
my controller
$form = $this->createForm('my_testbundle_club', $club); $request = $this->get('request'); if ($request->getMethod() == 'POST') { $form->submit($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($club); $em->flush(); } }
but when I submit my form without uploading anything (uploading is optional), I have an error saying that the column name in the File table cannot be null
but I want the download to be optional, but if there is a download, the name is required
How can i achieve this?
Thanks in advance.
source share