src/Form/ContactFormType.php line 41

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use Pimcore\Localization\LocaleService;
  4. use Pimcore\Translation\Translator;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\FormBuilderInterface;
  7. use Symfony\Component\OptionsResolver\OptionsResolver;
  8. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  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\ChoiceType;
  12. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  13. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  14. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  15. use Symfony\Component\Validator\Constraints\Type;
  16. use Symfony\Component\Validator\Constraints\IsTrue;
  17. use Symfony\Component\Validator\Constraints\Email;
  18. use Symfony\Component\Validator\Constraints\NotBlank;
  19. use Symfony\Component\Validator\Constraints\Choice;
  20. class ContactFormType extends AbstractType {
  21.     protected $locale;
  22.     protected $translator;
  23.     public function __construct(LocaleService $localeTranslator $translator) {
  24.         $this->locale $locale;
  25.         $this->translator $translator;
  26.     }
  27.     // forn name
  28.     /* public function getBlockPrefix() {
  29.         return 'contact_form';
  30.     } */
  31.     public function buildForm(FormBuilderInterface $builder, array $options) {
  32.         $builder
  33.             // ----------------------------------
  34.             // FIELDS
  35.             // ----------------------------------
  36.             // gender
  37.             /* ->add('gender', ChoiceType::class, [
  38.                 'label' => ' ',
  39.                 'label_attr' => [
  40.                     'class' => 'radio-label'
  41.                 ],
  42.                 'required' => true,
  43.                 'expanded' => true,
  44.                 'multiple' => false,
  45.                 'choices'  => [
  46.                     'form.contact.gender.male' => 'male',
  47.                     'form.contact.gender.female' => 'female'
  48.                 ],
  49.                 'error_bubbling' => true,
  50.                 'constraints' => [
  51.                     new Choice([
  52.                         'message' => $this->translator->trans('form.contact.gender.badchoice'),
  53.                         'choices' => [
  54.                             'male', 
  55.                             'female'
  56.                         ]
  57.                     ]),
  58.                     new NotBlank(['message' => $this->translator->trans('form.contact.gender.blank')])
  59.                 ]
  60.             ]) */
  61.             // firstname
  62.             ->add('firstname'TextType::class, [
  63.                 'label' => 'form.contact.firstname',
  64.                 'label_attr' => [
  65.                     'class' => 'form-input-label',
  66.                     'data-input' => 'contact_form_firstname'
  67.                 ],
  68.                 'attr' => [
  69.                     'placeholder' => ''//'form.contact.firstname',
  70.                     'class' => 'form-input'
  71.                 ],
  72.                 'required' => true,
  73.                 'error_bubbling' => true,
  74.                 'constraints' => [
  75.                     new NotBlank(['message' => $this->translator->trans('form.contact.firstname.blank')])
  76.                 ]
  77.             ])
  78.             // lastname
  79.             ->add('lastname'TextType::class, [
  80.                 'label' => 'form.contact.lastname',
  81.                 'label_attr' => [
  82.                     'class' => 'form-input-label',
  83.                     'data-input' => 'contact_form_lastname'
  84.                 ],
  85.                 'attr' => [
  86.                     'placeholder' => ''//'form.contact.lastname',
  87.                     'class' => 'form-input'
  88.                 ],
  89.                 'required' => true,
  90.                 'error_bubbling' => true,
  91.                 'constraints' => [
  92.                     new NotBlank(['message' => $this->translator->trans('form.contact.lastname.blank')])
  93.                 ]
  94.             ])
  95.             // phone
  96.             ->add('phone'TextType::class, [
  97.                 'label' => 'form.contact.phone',
  98.                 'label_attr' => [
  99.                     'class' => 'form-input-label',
  100.                     'data-input' => 'contact_form_phone'
  101.                 ],
  102.                 'attr' => [
  103.                     'placeholder' => ''//'form.contact.phone',
  104.                     'class' => 'form-input'
  105.                 ],
  106.                 'required' => true,
  107.                 'error_bubbling' => true,
  108.                 'constraints' => [
  109.                     new NotBlank(['message' => $this->translator->trans('form.contact.phone.blank')])
  110.                 ]
  111.             ])
  112.             // email
  113.             ->add('email'EmailType::class, [
  114.                 'label' => 'form.contact.email',
  115.                 'label_attr' => [
  116.                     'class' => 'form-input-label',
  117.                     'data-input' => 'contact_form_email'
  118.                 ],
  119.                 'attr' => [
  120.                     'placeholder' => ''//'form.contact.email',
  121.                     'class' => 'form-input'
  122.                 ],
  123.                 'required' => true,
  124.                 'error_bubbling' => true,
  125.                 'constraints' => [
  126.                     new NotBlank(['message' => $this->translator->trans('form.contact.email.blank')]),
  127.                     new Email(['message' => $this->translator->trans('form.contact.email.notvalid')])
  128.                 ]
  129.             ])
  130.             // message
  131.             ->add('message'TextareaType::class, [
  132.                 'label' => 'form.contact.message',
  133.                 'label_attr' => [
  134.                     'class' => 'form-textarea-label',
  135.                     'data-input' => 'contact_form_message'
  136.                 ],
  137.                 'attr' => [
  138.                     'placeholder' => ''//'form.contact.message',
  139.                     'class' => 'form-textarea',
  140.                     //'rows' => '7'
  141.                 ],
  142.                 'required' => true,
  143.                 'error_bubbling' => true,
  144.                 'constraints' => [
  145.                     new NotBlank(['message' => $this->translator->trans('form.contact.message.blank')])
  146.                 ]
  147.             ])
  148.             // agreement
  149.             ->add('agreement'CheckboxType::class, [
  150.                 'label' => 'form.contact.agreement',
  151.                 'label_attr' => [
  152.                     'class' => 'form-checkbox'
  153.                 ],
  154.                 'required' => true,
  155.                 'error_bubbling' => true,
  156.                 'constraints' => [
  157.                     new IsTrue(['message' => $this->translator->trans('form.contact.agreement.nottrue')])
  158.                 ]
  159.             ])
  160.             // ----------------------------------
  161.             // HIDDEN
  162.             // ----------------------------------
  163.             // hidden
  164.             ->add('hidden'HiddenType::class, [
  165.                 'required' => false
  166.             ])
  167.             // js filled
  168.             ->add('filled'HiddenType::class, [
  169.                 'required' => false
  170.             ])
  171.             // ----------------------------------
  172.             // SUBMIT
  173.             // ----------------------------------
  174.             // submit button
  175.             ->add('submit'SubmitType::class, [
  176.                 'label' => 'form.contact.submit',
  177.                 'attr' => [
  178.                     //'class' => 'button'
  179.                 ]
  180.             ])
  181.         ;
  182.     }
  183. }