]> Raphaël G. Git Repositories - packbundle/blob - Form/ContactType.php
Import contact form
[packbundle] / Form / ContactType.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys PackBundle 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\PackBundle\Form;
13
14 use Symfony\Component\Form\FormBuilderInterface;
15 use Symfony\Component\OptionsResolver\OptionsResolver;
16 use Symfony\Component\Form\Extension\Core\Type\TextType;
17 use Symfony\Component\Form\Extension\Core\Type\TextareaType;
18 use Symfony\Component\Form\Extension\Core\Type\EmailType;
19 use Symfony\Component\Form\Extension\Core\Type\SubmitType;
20 use Symfony\Component\Validator\Constraints\Email;
21 use Symfony\Component\Validator\Constraints\NotBlank;
22
23 /**
24 * {@inheritdoc}
25 */
26 class ContactType extends CaptchaType {
27 /**
28 * {@inheritdoc}
29 */
30 public function buildForm(FormBuilderInterface $builder, array $options): void {
31 //Add fields
32 $builder
33 ->add('name', TextType::class, ['attr' => ['placeholder' => 'Your name'], 'constraints' => [new NotBlank(['message' => 'Please provide your name'])]])
34 ->add('subject', TextType::class, ['attr' => ['placeholder' => 'Subject'], 'constraints' => [new NotBlank(['message' => 'Please provide your subject'])]])
35 ->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'])]])
36 ->add('message', TextareaType::class, ['attr' => ['placeholder' => 'Your message', 'cols' => 50, 'rows' => 15], 'constraints' => [new NotBlank(['message' => 'Please provide your message'])]])
37 ->add('submit', SubmitType::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]);
38
39 //Call parent
40 parent::buildForm($builder, $options);
41 }
42
43 /**
44 * {@inheritdoc}
45 */
46 public function configureOptions(OptionsResolver $resolver): void {
47 //Call parent configure options
48 parent::configureOptions($resolver);
49
50 //Set defaults
51 $resolver->setDefaults(['captcha' => true]);
52 }
53
54 /**
55 * {@inheritdoc}
56 */
57 public function getName() {
58 return 'contact_form';
59 }
60 }