src/Form/Type/ParticipantFormType.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Form\Type;
  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\EmailType;
  8. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use App\Entity\Participant;
  12. use App\Entity\Competition;
  13. class ParticipantFormType extends AbstractType {
  14.     public function buildForm(FormBuilderInterface $builder, array $options) {
  15.         $builder
  16.                 ->add('name'TextType::class, [
  17.                     'required' => true,
  18.                     'constraints' => [
  19.                         new Assert\NotBlank([
  20.                             'message' => 'Please enter your name'
  21.                                 ])
  22.                     ]
  23.                 ])
  24.                 ->add('teamName'TextType::class, [
  25.                     'required' => true,
  26.                     'constraints' => [
  27.                         new Assert\NotBlank([
  28.                             'message' => "Please enter your team's name"
  29.                                 ])
  30.                     ]
  31.                 ])
  32.                 ->add('email'EmailType::class, [
  33.                     'required' => true,
  34.                     'constraints' => [
  35.                         new Assert\NotBlank([
  36.                             'message' => 'Please enter your email'
  37.                                 ])
  38.                     ]
  39.                 ])
  40.                 ->add('phoneNumber'TextType::class, [
  41.                     'required' => true,
  42.                     'constraints' => [
  43.                         new Assert\NotBlank([
  44.                             'message' => 'Please enter your phone number'
  45.                                 ])
  46.                     ]
  47.                 ])
  48.                 ->add('downPaymentAmount'NumberType::class, [
  49.                     'required' => true,
  50.                     'html5' => true,
  51.                     'attr' => [
  52.                         'min' => $options['minimum_down_payment'],
  53.                         'step' => 1
  54.                     ],
  55.                     'constraints' => [
  56.                         new Assert\NotBlank([
  57.                             'message' => 'Please enter your down payment amount'
  58.                                 ]),
  59.                         new Assert\GreaterThanOrEqual([
  60.                             'value' => $options['minimum_down_payment'],
  61.                             'message' => sprintf('The minimum down payment amount is %s'$options['minimum_down_payment'])
  62.                                 ])
  63.                     ]
  64.                 ])
  65.                 ->add('message'TextareaType::class, [
  66.                     'required' => false
  67.                 ])
  68.         ;
  69.     }
  70.     public function configureOptions(OptionsResolver $resolver) {
  71.         $resolver->setDefaults(array(
  72.             'data_class' => Participant::class,
  73.             'minimum_down_payment' => Competition::MINIMUM_DOWN_PAYMENT,
  74.             'allow_extra_fields' => true
  75.         ));
  76.     }
  77. }