Skip to content

Commit 21c4c9f

Browse files
mickaelandrieujaviereguiluz
authored andcommitted
Added a note on forms validation
1 parent 70d6ce0 commit 21c4c9f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

best_practices/forms.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,27 @@ view layer:
145145
class="btn btn-default pull-right" />
146146
{{ form_end(form) }}
147147

148+
Validation
149+
----------
150+
151+
Define your validation constraints outside of the forms, for instance directly on the object
152+
class used as data mapper::
153+
154+
// src/Entity/Post.php
155+
156+
// ...
157+
use Symfony\Component\Validator\Constraints as Assert;
158+
159+
class Post
160+
{
161+
/**
162+
* @Assert\NotBlank()
163+
*/
164+
public $title;
165+
}
166+
167+
This make them reusables and independents from the validation rules.
168+
148169
Rendering the Form
149170
------------------
150171

0 commit comments

Comments
 (0)