Skip to content

(Proposal) Added a note on forms validation #10331

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 1 commit
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
21 changes: 21 additions & 0 deletions best_practices/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,27 @@ view layer:
<input type="submit" class="btn" value="Create" />
{{ form_end(form) }}

Validation
----------

Define your validation constraints outside of the forms, for instance directly on the object
class used as data mapper::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe reword it a bit like this:

Do not define your validation constraint with the constraints option. Configure them on the object the form is mapped to instead:


// src/Entity/Post.php

// ...
use Symfony\Component\Validator\Constraints as Assert;

class Post
{
/**
* @Assert\NotBlank()
*/
public $title;
}

This make them reusables and independents from the validation rules.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

independent


Rendering the Form
------------------

Expand Down