<?php
namespace App\Form;
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\ChoiceType;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Positive;
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\Email;
class DonateType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('price', ChoiceType::class, [
'row_attr' => ['class' => 'text-editor', 'id' => '...'],
'choices' => [
'3' => 3,
'5' => 5,
'10' => 10,
'25' => 25,
],
'label' => 'Montant',
'translation_domain' => 'messages',
'choice_attr' =>[
'class' => 'cssClassName' //won't work
],
'data' => '3',
'expanded' => true,
'multiple' => false,
'error_bubbling' => true,
'constraints' => [
new NotBlank(),
new Positive(),
new Choice([3, 5,10,25]),
],
]
)
->add('other',textType::class, array('required' => false,
'translation_domain' => 'messages',
'label'=>'donate.otheramount',
'attr' => array('class' => 'input-text','placeholder'=>'header.donate.otheramount','translation_domain' => 'messages'),
'translation_domain' => 'messages',
'error_bubbling' => true,
'constraints' => [
new Positive(),
],
)
)
->add('name',textType::class, array('required' => false,
'translation_domain' => 'messages',
'label'=>'Name',
'error_bubbling' => true,
'attr' => array('class' => 'input-text'),
'constraints' => [
new NotBlank(),
],
)
)
->add('email',textType::class, array('required' => false,
'translation_domain' => 'messages',
'label'=>'Email',
'error_bubbling' => true,
'attr' => array('class' => 'input-text'),
'constraints' => [
new Email(),
new NotBlank(),
],
)
)
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(['error_bubbling', true]);
}
}