8000 Complete code example for "Adding validation" part by welcoMattic · Pull Request #10780 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Complete code example for "Adding validation" part #10780

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
Next Next commit
Complete code example for "Adding validation" part
  • Loading branch information
welcoMattic authored Dec 13, 2018
commit fc1954cd9deb985aa34a8723ba3e34381ff05901
27 changes: 15 additions & 12 deletions form/without_class.rst
9654
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,22 @@ but here's a short example::
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

$builder
->add('firstName', TextType::class, array(
'constraints' => new Length(array('min' => 3)),
))
->add('lastName', TextType::class, array(
'constraints' => array(
new NotBlank(),
new Length(array('min' => 3)),
),
))
;

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('firstName', TextType::class, array(
'constraints' => new Length(array('min' => 3)),
))
->add('lastName', TextType::class, array(
'constraints' => array(
new NotBlank(),
new Length(array('min' => 3)),
),
))
;
}
.. tip::

If you are using validation groups, you need to either reference the
Expand Down
0