src/Form/ContactFormType.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use Symfony\Component\Form\AbstractType;
  4. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  5. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  6. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  7. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  8. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. use Symfony\Component\Intl\Countries;
  12. use Symfony\Component\OptionsResolver\OptionsResolver;
  13. class ContactFormType extends AbstractType
  14. {
  15.     /**
  16.      * @inheritDoc
  17.      */
  18.     public function buildForm(FormBuilderInterface $builder, array $options)
  19.     {
  20.         $countryChoices Countries::getNames();
  21.         $belgium $countryChoices['BE'];
  22.         unset($countryChoices['BelgiĆ«']);
  23.         $countryChoices = ['BelgiĆ«' => $belgium] + $countryChoices;
  24.         $builder
  25.             ->add('firstname'TextType::class, [
  26.                 'label'       => 'Firstname',
  27.                 'required'    => true
  28.             ])
  29.             ->add('lastname'TextType::class, [
  30.                 'label'    => 'Lastname',
  31.                 'required' => true
  32.             ])
  33.             ->add('about'ChoiceType::class, [
  34.                 'choices' => [
  35.                     'Make a choice' => '',
  36.                     'Zeilen' => 'Z',
  37.                     'Suppen' => 'S',
  38.                     'Windsurfen' => 'W',
  39.                 ],
  40.                 'required' => true,
  41.             ])
  42.             ->add('email'EmailType::class, [
  43.                 'label'    => 'E-Mail',
  44.                 'required' => true,
  45.                 'attr'     => [
  46.                     'placeholder' => 'example@example.com'
  47.                 ]
  48.             ])
  49.             ->add('country'ChoiceType::class, [
  50.                 'label' => 'Land',
  51.                 'choices' => array_flip($countryChoices),
  52.                 'required' => true,
  53.             ])
  54.             ->add('message'TextareaType::class, [
  55.                 'label'    => 'Message',
  56.                 'required' => true
  57.             ])
  58.             ->add('conditions'CheckboxType::class, [
  59.                 'label'    => 'Conditions',
  60.                 'required' => true
  61.             ])
  62.             ->add('submit'SubmitType::class, [
  63.                 'label' => 'Submit'
  64.             ]);
  65.     }
  66.     /**
  67.      * @inheritDoc
  68.      */
  69.     public function configureOptions(OptionsResolver $resolver)
  70.     {
  71.     }
  72. }