diff --git a/form/without_class.rst b/form/without_class.rst index 29c8fdbfe2c..e0a6959582e 100644 --- a/form/without_class.rst +++ b/form/without_class.rst @@ -82,18 +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::