0

I'm trying to create a form that have some optional fields (leave them blank), to do this i've added the required => false option to the formbuilder...

$builder->add('twitter', 'url', array('required' => 'false'));

The Entity doesn't have any Validation Constraints...

/**
 * @var string
 *
 * @ORM\Column(name="twitter", type="string", length=50)
 */
private $twitter;

Also tried to clear the cache in dev, prod with debug true/false. But the form still have the required attribute when it loads :$

<input type="url" id="post_add_twitter" name="post_add[twitter]" required="required" />

My setup passes the php app/check.php

What i'm doing wrong ?

EDITED: Symfony version 2.1.7, PHP version 5.4.7

2
  • Symfony 2.4.7? I think 2.2 is not out yet. Your php version does not make sense either. Commented Jan 30, 2013 at 1:19
  • Ops, my mistake... Completely mixed the numbers :$ Edited and ty for reporting. (Autonote: Go sleep...) Commented Jan 30, 2013 at 4:06

1 Answer 1

2

The 'required' attribute takes a boolean, not a string:

$builder->add('twitter', 'url', array('required' => false));

I haven't looked too deep, but I would imagine that this attribute is type-cast at some point, meaning any string (other than '') will evaluate to true, and force your field into being required

Sign up to request clarification or add additional context in comments.

1 Comment

You're right. I was passing the string 'false' and not a boolean value. ¬¬ I'm Too dumb tonight... Haha MatW ty for helping ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.