user1000652
user1000652

Reputation: 33

Symfony form validation.

I'm just a beginner with Symfony.

Here is my Member Entity with field "login".

/**
 * @var string
 *
 * @ORM\Column(name="login", type="string", length=255, nullable=false)
 */
private $login;

}

In the controller I call

function addAction(Request $request){ $member = new Member();

    $formBuilder = $this->get('form.factory')->createBuilder('form', $member);

    // We add required fields
   $formBuilder ->add('login','text', 'required' => true)

}

Does the form check the required of the login field when I call // We verify if the form is valid if ($form->isValid()) { }

Upvotes: 0

Views: 97

Answers (2)

Mateusz Brychcy
Mateusz Brychcy

Reputation: 1

You can add constraint when building form field. Try this:

$formBuilder -> add('login','text', array(
     'constraints' => new NotBlank())
);

More info you can find at http://symfony.com/doc/current/components/form/introduction.html#form-validation

Upvotes: 0

Koalabaerchen
Koalabaerchen

Reputation: 575

Required only adds the input attribute required="required" to the html and is not a validation.

For more infos on actual form validation check out http://symfony.com/doc/current/book/validation.html

Yours would be the NotNull or NotBlank validation

Upvotes: 2

Related Questions