Advertisement
SanderCokart

TodoType.php

Mar 3rd, 2020
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.83 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Form;
  4.  
  5. use App\Entity\Todo;
  6. use Symfony\Component\Form\AbstractType;
  7. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  8. use Symfony\Component\Form\Extension\Core\Type\TextType;
  9. use Symfony\Component\Form\FormBuilderInterface;
  10. use Symfony\Component\OptionsResolver\OptionsResolver;
  11. use Symfony\Component\Validator\Constraints\Length;
  12. use Symfony\Component\Validator\Constraints\NotBlank;
  13.  
  14. class TodoType extends AbstractType
  15. {
  16.     public function buildForm(FormBuilderInterface $builder, array $options)
  17.     {
  18.         $builder
  19.             ->add('task', TextType::class, [
  20.                 'constraints' => [
  21.                     new NotBlank(['message' => 'Task name cannot be blank!']),
  22.                     new Length([
  23.                         'min' => 1,
  24.                         'max' => 10,
  25.  
  26.                         'minMessage' => 'Enter at least 1 character!',
  27.                         'maxMessage' => 'You entered {{ value }} but you can not use more than {{ limit }} characters!',
  28.                     ])
  29.                 ]
  30.             ])
  31.             ->add('description', TextareaType::class, [
  32.                 'constraints' => [
  33.                     new NotBlank(['message' => 'The description cannot be blank!']),
  34.                     new Length([
  35.                         'min' => 1,
  36.                         'max' => 500,
  37.  
  38.                         'minMessage' => 'Enter at least 1 character!',
  39.                         'maxMessage' => 'You entered {{ value }} but you can not use more than {{ limit }} characters!',
  40.                     ])
  41.                 ]
  42.             ])
  43.         ;
  44.     }
  45.  
  46.     public function configureOptions(OptionsResolver $resolver)
  47.     {
  48.         $resolver->setDefaults([
  49.             'data_class' => Todo::class,
  50.             'csrf_protection' => false,
  51.         ]);
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement