src/Form/DonateType.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use Symfony\Component\Form\AbstractType;
  4. use Symfony\Component\Form\FormBuilderInterface;
  5. use Symfony\Component\OptionsResolver\OptionsResolver;
  6. use Symfony\Component\Form\Extension\Core\Type\TextType;
  7. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  8. use Symfony\Component\Validator\Constraints\Length;
  9. use Symfony\Component\Validator\Constraints\NotBlank;
  10. use Symfony\Component\Validator\Constraints\Positive;
  11. use Symfony\Component\Validator\Constraints\Choice;
  12. use Symfony\Component\Validator\Constraints\Email;
  13. class DonateType extends AbstractType
  14. {
  15.     public function buildForm(FormBuilderInterface $builder, array $options)
  16.     {
  17.         $builder
  18.             ->add('price'ChoiceType::class, [
  19.                     'row_attr' => ['class' => 'text-editor''id' => '...'],
  20.                     'choices'  => [
  21.                         '3' => 3,
  22.                         '5' => 5,
  23.                         '10' => 10,
  24.                         '25' => 25,
  25.                     ],
  26.                     'label' => 'Montant',
  27.                     'translation_domain' => 'messages',
  28.                     'choice_attr' =>[
  29.                         'class' => 'cssClassName' //won't work
  30.                         ],
  31.                     'data' => '3',
  32.                     'expanded' => true,
  33.                     'multiple' => false,
  34.                     'error_bubbling' => true,
  35.                     'constraints' => [
  36.                         new NotBlank(),
  37.                         new Positive(),
  38.                         new Choice([35,10,25]),
  39.                     ],
  40.                 ]
  41.             )
  42.             ->add('other',textType::class, array('required' => false,
  43.                     'translation_domain' => 'messages',
  44.                     'label'=>'donate.otheramount',
  45.                     'attr' => array('class' => 'input-text','placeholder'=>'header.donate.otheramount','translation_domain' => 'messages'),
  46.                     'translation_domain' => 'messages',
  47.                     'error_bubbling' => true,
  48.                     'constraints' => [
  49.                         new Positive(),
  50.                     ],
  51.                 )
  52.             )
  53.             ->add('name',textType::class, array('required' => false,
  54.                     'translation_domain' => 'messages',
  55.                     'label'=>'Name',
  56.                     'error_bubbling' => true,
  57.                     'attr' => array('class' => 'input-text'),
  58.                     'constraints' => [
  59.                         new NotBlank(),
  60.                     ],
  61.                 )
  62.             )
  63.             ->add('email',textType::class, array('required' => false,
  64.                     'translation_domain' => 'messages',
  65.                     'label'=>'Email',
  66.                     'error_bubbling' => true,
  67.                     'attr' => array('class' => 'input-text'),
  68.                     'constraints' => [
  69.                         new Email(),
  70.                         new NotBlank(),
  71.                     ],
  72.                 )
  73.             )
  74.          
  75.         ;
  76.     }
  77.     public function configureOptions(OptionsResolver $resolver)
  78.     {
  79.                 $resolver->setDefaults(['error_bubbling'true]);
  80.     }
  81. }