Validating form without Doctrine Entity

前端 未结 1 1037
无人及你
无人及你 2020-12-30 21:20

I have a situation where I need to validate a form without actually having an object to store anywhere. In this scenario, would I still create an Entity without doctrine and

相关标签:
1条回答
  • See the Using a Form without a Class section — there is a subsection on validation, too.

    The answer is to setup the constraints yourself, and attach them to the individual fields.

    use Symfony\Component\Validator\Constraints\Length;
    use Symfony\Component\Validator\Constraints\NotBlank;
    
    $builder
       ->add('firstName', 'text', array(
           'constraints' => new Length(array('min' => 3)),
       ))
       ->add('lastName', 'text', array(
           'constraints' => array(
               new NotBlank(),
               new Length(array('min' => 3)),
           ),
       ))
    ;
    
    0 讨论(0)
提交回复
热议问题