Note that there are some explanatory texts on larger screens.

plurals
  1. POForm validation ignores empty value
    primarykey
    data
    text
    <p>FormType:</p> <pre><code>class BranchFormType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder-&gt;add('name'); } public function getName() { return 'branch'; } public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver-&gt;setDefaults(array( 'data_class' =&gt; 'My\MainBundle\Entity\Branch', )); } } </code></pre> <p>In entity definition:</p> <pre><code>&lt;field name="name" column="name" type="string" length="255"/&gt; </code></pre> <p>there is no nullable=true and the field has required attribute when rendered.</p> <p>Validation.yml:</p> <pre><code>My\MainBundle\Entity\Branch: properties: name: - NotBlank: ~ </code></pre> <p>Does symfony find this file automatically or do I have to included somewhere? The doc just states that the form uses validation service automatically.</p> <p>Controller:</p> <pre><code> $branch = new Branch(); $form = $this-&gt;createForm(new BranchFormType(), $branch); if ($request-&gt;isMethod('POST')) { $form-&gt;bindRequest($request); if ($form-&gt;isValid()) { $em-&gt;persist($branch); $em-&gt;flush(); return $this-&gt;redirect($this-&gt;generateUrl('view_branch')); } } return $this-&gt;render('MyMainBundle:Branch:create.html.twig', array( 'form' =&gt; $form-&gt;createView() )); </code></pre> <p>On submit I get following error:</p> <blockquote> <p>SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null</p> </blockquote> <p>So isValid returns true despite the fact that name is empty and continues to persist the entity with empty values. How can isValid return true when the name is empty? ORM definition says nullable=false?`Any ideas? I have no extra validator defined. I use sf2.1</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload