]> Raphaël G. Git Repositories - airbundle/blob - Form/ContactType.php
Use new form name
[airbundle] / Form / ContactType.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys AirBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\AirBundle\Form;
13
14 use Rapsys\PackBundle\Form\CaptchaType;
15
16 use Symfony\Component\Form\FormBuilderInterface;
17 use Symfony\Component\OptionsResolver\OptionsResolver;
18 use Symfony\Component\Form\Extension\Core\Type\TextType;
19 use Symfony\Component\Form\Extension\Core\Type\TextareaType;
20 use Symfony\Component\Form\Extension\Core\Type\EmailType;
21 use Symfony\Component\Form\Extension\Core\Type\SubmitType;
22 use Symfony\Component\Validator\Constraints\Email;
23 use Symfony\Component\Validator\Constraints\NotBlank;
24
25 /**
26 * {@inheritdoc}
27 */
28 class ContactType extends CaptchaType {
29 /**
30 * {@inheritdoc}
31 */
32 public function buildForm(FormBuilderInterface $builder, array $options): void {
33 //Add fields
34 $builder
35 ->add('name', TextType::class, ['attr' => ['placeholder' => 'Your name'], 'constraints' => [new NotBlank(['message' => 'Please provide your name'])]])
36 ->add('subject', TextType::class, ['attr' => ['placeholder' => 'Subject'], 'constraints' => [new NotBlank(['message' => 'Please provide your subject'])]])
37 ->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'])]])
38 ->add('message', TextareaType::class, ['attr' => ['placeholder' => 'Your message', 'cols' => 50, 'rows' => 15], 'constraints' => [new NotBlank(['message' => 'Please provide your message'])]])
39 ->add('submit', SubmitType::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]);
40
41 //Call parent
42 parent::buildForm($builder, $options);
43 }
44
45 /**
46 * {@inheritdoc}
47 */
48 public function configureOptions(OptionsResolver $resolver): void {
49 //Set defaults
50 $resolver->setDefaults(['error_bubbling' => true]);
51 }
52
53 /**
54 * {@inheritdoc}
55 */
56 public function getName(): string {
57 return 'contact_form';
58 }
59 }