<?php
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Validator\Constraints as Assert;
use App\Entity\Participant;
use App\Entity\Competition;
class ParticipantFormType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('name', TextType::class, [
'required' => true,
'constraints' => [
new Assert\NotBlank([
'message' => 'Please enter your name'
])
]
])
->add('teamName', TextType::class, [
'required' => true,
'constraints' => [
new Assert\NotBlank([
'message' => "Please enter your team's name"
])
]
])
->add('email', EmailType::class, [
'required' => true,
'constraints' => [
new Assert\NotBlank([
'message' => 'Please enter your email'
])
]
])
->add('phoneNumber', TextType::class, [
'required' => true,
'constraints' => [
new Assert\NotBlank([
'message' => 'Please enter your phone number'
])
]
])
->add('downPaymentAmount', NumberType::class, [
'required' => true,
'html5' => true,
'attr' => [
'min' => $options['minimum_down_payment'],
'step' => 1
],
'constraints' => [
new Assert\NotBlank([
'message' => 'Please enter your down payment amount'
]),
new Assert\GreaterThanOrEqual([
'value' => $options['minimum_down_payment'],
'message' => sprintf('The minimum down payment amount is %s', $options['minimum_down_payment'])
])
]
])
->add('message', TextareaType::class, [
'required' => false
])
;
}
public function configureOptions(OptionsResolver $resolver) {
$resolver->setDefaults(array(
'data_class' => Participant::class,
'minimum_down_payment' => Competition::MINIMUM_DOWN_PAYMENT,
'allow_extra_fields' => true
));
}
}