]> Raphaƫl G. Git Repositories - airbundle/blob - Form/ContactType.php
Fix configuration tree
[airbundle] / Form / ContactType.php
1 <?php
2
3 namespace Rapsys\AirBundle\Form;
4
5 use Rapsys\PackBundle\Form\CaptchaType;
6
7 use Symfony\Component\Form\FormBuilderInterface;
8 use Symfony\Component\OptionsResolver\OptionsResolver;
9 use Symfony\Component\Form\Extension\Core\Type\TextType;
10 use Symfony\Component\Form\Extension\Core\Type\TextareaType;
11 use Symfony\Component\Form\Extension\Core\Type\EmailType;
12 use Symfony\Component\Form\Extension\Core\Type\SubmitType;
13 use Symfony\Component\Validator\Constraints\Email;
14 use Symfony\Component\Validator\Constraints\NotBlank;
15
16 class ContactType extends CaptchaType {
17 /**
18 * {@inheritdoc}
19 */
20 public function buildForm(FormBuilderInterface $builder, array $options): void {
21 //Add fields
22 $builder
23 ->add('name', TextType::class, ['attr' => ['placeholder' => 'Your name'], 'constraints' => [new NotBlank(['message' => 'Please provide your name'])]])
24 ->add('subject', TextType::class, ['attr' => ['placeholder' => 'Subject'], 'constraints' => [new NotBlank(['message' => 'Please provide your subject'])]])
25 ->add('mail', EmailType::class, ['attr' => ['placeholder' => 'Your mail'], 'constraints' => [new NotBlank(['message' => 'Please provide a valid mail']), new Email(['message' => 'Your mail doesn\'t seems to be valid'])]])
26 ->add('message', TextareaType::class, ['attr' => ['placeholder' => 'Your message', 'cols' => 50, 'rows' => 15], 'constraints' => [new NotBlank(['message' => 'Please provide your message'])]])
27 ->add('submit', SubmitType::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]);
28
29 //Call parent
30 parent::buildForm($builder, $options);
31 }
32
33 /**
34 * {@inheritdoc}
35 */
36 public function configureOptions(OptionsResolver $resolver) {
37 //Set defaults
38 $resolver->setDefaults(['error_bubbling' => true]);
39 }
40
41 /**
42 * {@inheritdoc}
43 */
44 public function getName() {
45 return 'contact_form';
46 }
47 }