Skip to content

Add an explanation about «constraints» validation #7664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,29 @@ If you're ever unsure of how to specify an option, either check the API document
for the constraint or play it safe by always passing in an array of options
(the first method shown above).

Constraints in Form Classes
---------------------------

Constraints can be defined while building the form via the ``constraints`` option
of the form fields::

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('myField', TextType::class, array(
'required' => true,
'constraints' => array(new Length(array('min' => 3)))
))
}

The ``constraints`` option is only available when adding the ValidatorExtention
to the formBuilder::

Forms::createFormFactoryBuilder()
->addExtension(new ValidatorExtension(Validation::createValidator()))
->getFormFactory()
;

.. index::
single: Validation; Constraint targets

Expand Down