src/Form/ContactType.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Countries;
  4. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  7. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  8. use Symfony\Component\Form\Extension\Core\Type\TelType;
  9. use Symfony\Component\Form\Extension\Core\Type\UrlType;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. use Symfony\Component\OptionsResolver\OptionsResolver;
  12. class ContactType extends AbstractType
  13. {
  14.     public function buildForm(FormBuilderInterface $builder, array $options)
  15.     {
  16.         $builder
  17.             ->add('subject'null, ['attr' => ['rows' => 4'cols' => 30'maxlength' => 255], 'required' => true'label' => 'Comment'])
  18.             ->add('url'null, ['attr' => ['placeholder' => 'Url''maxlength' => 245], 'required' => true'label' => false])
  19.             ->add('name'null, ['attr' => ['placeholder' => 'Name''maxlength' => 255], 'required' => true'label' => false])
  20.             ->add('company'null, ['attr' => ['placeholder' => 'Company''maxlength' => 255], 'required' => false'label' => false])
  21.             ->add('email'EmailType::class, ['attr' => ['placeholder' => 'Email''maxlength' => 255], 'required' => true'label' => false])
  22.             ->add('phone'TelType::class, ['attr' => ['placeholder' => 'Phone''maxlength' => 255], 'required' => true'label' => false])
  23.             ->add('country'EntityType::class, [
  24.                 'class' => Countries::class,
  25.                 'choice_name' => 'title',
  26.                 'required' => true,
  27.                 'label' => false,
  28.                 'attr' => ['class' => 'required valid'],
  29.                 'choice_translation_domain' => true,
  30.             ])
  31.             ->add('hear'null, ['attr' => ['placeholder' => 'How did you hear about us?''maxlength' => 255], 'required' => true'label' => false])
  32.         ;
  33.         if($_ENV['GOOGLE_RECAPTCHA_ENABLED'] === 'true')
  34.         {
  35.             $builder
  36.                 ->add('recaptcha'HiddenType::class, [
  37.                     'mapped' => false,
  38.                 ])
  39.             ;
  40.         }
  41.     }
  42.     public function setDefaultOptions(OptionsResolver $resolver): void
  43.     {
  44.         $resolver->setDefaults(array(
  45.             'data_class' => 'Entity\Contact'
  46.         ));
  47.     }
  48.     public function getName(): string
  49.     {
  50.         return 'contact';
  51.     }
  52. }