src/Form/OrderFormType.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Order;
  4. use App\Entity\Template;
  5. use Eckinox\TinymceBundle\Form\Type\TinymceType;
  6. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  7. use Symfony\Component\Form\AbstractType;
  8. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  9. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  10. use Symfony\Component\Form\Extension\Core\Type\DateType;
  11. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  12. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  13. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  14. use Symfony\Component\Form\Extension\Core\Type\TextType;
  15. use Symfony\Component\Form\FormBuilderInterface;
  16. use Symfony\Component\OptionsResolver\OptionsResolver;
  17. use Symfony\Component\Validator\Constraints\IsTrue;
  18. use Symfony\Component\Validator\Constraints\NotBlank;
  19. class OrderFormType extends AbstractType
  20. {
  21.     public function buildForm(FormBuilderInterface $builder, array $options): void
  22.     {
  23.         $builder
  24.             ->add('deliveryFirstname'TextType::class, [
  25.                 'required' => false,
  26.                 'label' => 'First name',
  27.                 'row_attr' => [
  28.                     'class' => 'form-floating mb-3',
  29.                 ],
  30.                 'mapped' => false,
  31.             ])
  32.             ->add('deliveryLastname'TextType::class, [
  33.                 'required' => false,
  34.                 'label' => 'Last name',
  35.                 'row_attr' => [
  36.                     'class' => 'form-floating mb-3',
  37.                 ],
  38.                 'mapped' => false,
  39.             ])
  40.             ->add('deliveryCountry'TextType::class, [
  41.                 'required' => false,
  42.                 'label' => 'Country',
  43.                 'row_attr' => [
  44.                     'class' => 'form-floating mb-3',
  45.                 ],
  46.                 'mapped' => false,
  47.             ])
  48.             ->add('deliveryCity'TextType::class, [
  49.                 'required' => false,
  50.                 'label' => 'City',
  51.                 'row_attr' => [
  52.                     'class' => 'form-floating mb-3',
  53.                 ],
  54.                 'mapped' => false,
  55.             ])
  56.             ->add('deliveryZipcode'TextType::class, [
  57.                 'required' => false,
  58.                 'label' => 'Zipcode',
  59.                 'row_attr' => [
  60.                     'class' => 'form-floating mb-3',
  61.                 ],
  62.                 'mapped' => false,
  63.             ])
  64.             ->add('deliveryStreet'TextType::class, [
  65.                 'required' => false,
  66.                 'label' => 'Street',
  67.                 'row_attr' => [
  68.                     'class' => 'form-floating mb-3',
  69.                 ],
  70.                 'mapped' => false,
  71.             ])
  72.             ->add('deliveryStreet2'TextType::class, [
  73.                 'label' => 'Apt. nr., floor',
  74.                 'row_attr' => [
  75.                     'class' => 'form-floating mb-3',
  76.                 ],
  77.                 'mapped' => false,
  78.                 'required' => false,
  79.             ])
  80.             ->add('billingFirstname'TextType::class, [
  81.                 'required' => true,
  82.                 'label' => 'First name',
  83.                 'row_attr' => [
  84.                     'class' => 'form-floating mb-3',
  85.                 ],
  86.                 'constraints' => [
  87.                     new NotBlank([
  88.                         'message' => 'Vyplňte vaše jméno',
  89.                     ]),
  90.                 ],
  91.                 'mapped' => false,
  92.             ])
  93.             ->add('billingLastname'TextType::class, [
  94.                 'required' => true,
  95.                 'label' => 'Last name',
  96.                 'row_attr' => [
  97.                     'class' => 'form-floating mb-3',
  98.                 ],
  99.                 'constraints' => [
  100.                     new NotBlank([
  101.                         'message' => 'Vyplňte vaše příjmení',
  102.                     ]),
  103.                 ],
  104.                 'mapped' => false,
  105.             ])
  106.             ->add('billingCountry'TextType::class, [
  107.                 'required' => true,
  108.                 'row_attr' => [
  109.                     'class' => 'form-floating mb-3',
  110.                 ],
  111.                 'constraints' => [
  112.                     new NotBlank([
  113.                         'message' => 'Vyplňte zemi',
  114.                     ]),
  115.                 ],
  116.                 'label' => 'Country',
  117.                 'mapped' => false,
  118.             ])
  119.             ->add('billingCity'TextType::class, [
  120.                 'required' => true,
  121.                 'row_attr' => [
  122.                     'class' => 'form-floating mb-3',
  123.                 ],
  124.                 'constraints' => [
  125.                     new NotBlank([
  126.                         'message' => 'Vyplňte město',
  127.                     ]),
  128.                 ],
  129.                 'label' => 'City',
  130.                 'mapped' => false,
  131.             ])
  132.             ->add('billingZipcode'TextType::class, [
  133.                 'required' => true,
  134.                 'row_attr' => [
  135.                     'class' => 'form-floating mb-3',
  136.                 ],
  137.                 'constraints' => [
  138.                     new NotBlank([
  139.                         'message' => 'Vyplňte PSČ',    
  140.                     ]),
  141.                 ],
  142.                 'label' => 'Zipcode',
  143.                 'mapped' => false,
  144.             ])
  145.             ->add('billingStreet'TextType::class, [
  146.                 'required' => true,
  147.                 'row_attr' => [
  148.                     'class' => 'form-floating mb-3',
  149.                 ],
  150.                 'constraints' => [
  151.                     new NotBlank([
  152.                         'message' => 'Vyplňte adresu',
  153.                     ]),
  154.                 ],
  155.                 'label' => 'Street',
  156.                 'mapped' => false,
  157.             ])
  158.             ->add('billingStreet2'TextType::class, [
  159.                 'label' => 'Apt. nr., floor',
  160.                 'row_attr' => [
  161.                     'class' => 'form-floating mb-3',
  162.                 ],
  163.                 'mapped' => false,
  164.                 'required' => false,
  165.             ])
  166.             ->add('deliveryEmail'EmailType::class, [
  167.                 'required' => false,
  168.                 'label' => 'Your e-mail address',
  169.                 'row_attr' => [
  170.                     'class' => 'form-floating mb-3',
  171.                 ],
  172.                 'constraints' => [
  173.                     new NotBlank([
  174.                         'message' => 'Vyplňte emailovou adresu',
  175.                     ]),
  176.                 ],
  177.                 'mapped' => false,
  178.             ])
  179.             ->add('deliveryPhone'NumberType::class, [
  180.                 'required' => false,
  181.                 'row_attr' => [
  182.                     'class' => 'form-floating mb-3',
  183.                 ],
  184.                 'constraints' => [
  185.                     new NotBlank([
  186.                         'message' => 'Vyplňte telefonní číslo',
  187.                     ]),
  188.                 ],
  189.                 'label' => 'Phone number',
  190.                 'mapped' => false,
  191.             ])
  192.             ->add('billingEmail'EmailType::class, [
  193.                 'required' => true,
  194.                 'label' => 'Your e-mail address',
  195.                 'row_attr' => [
  196.                     'class' => 'form-floating mb-3',
  197.                 ],
  198.                 'constraints' => [
  199.                     new NotBlank([
  200.                         'message' => 'Vyplňte emailovou adresu',
  201.                     ]),
  202.                 ],
  203.                 'mapped' => false,
  204.             ])
  205.             ->add('billingPhone'NumberType::class, [
  206.                 'required' => true,
  207.                 'row_attr' => [
  208.                     'class' => 'form-floating mb-3',
  209.                 ],
  210.                 'constraints' => [
  211.                     new NotBlank([
  212.                         'message' => 'Vyplňte telefonní číslo',
  213.                     ]),
  214.                 ],
  215.                 'label' => 'Phone number',
  216.                 'mapped' => false,
  217.             ])
  218.             ->add('text'TinymceType::class, [
  219.                 'required' => true,
  220.                 'row_attr' => [
  221.                     'class' => 'form-floating mb-3',
  222.                 ],
  223.                 'attr' => [
  224.                     'toolbar' => 'undo redo | casechange blocks | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist checklist outdent indent | removeformat | a11ycheck'
  225.                 ],
  226.                 'constraints' => [
  227.                     new NotBlank([
  228.                         'message' => 'Vyplňte text zprávy',
  229.                     ]),
  230.                 ],
  231.                 'label' => 'Message text',
  232.                 'mapped' => false,
  233.             ])
  234.             ->add('deliveryDate'DateType::class, [
  235.                 'required' => true,
  236.                 'row_attr' => [
  237.                     'class' => 'form-floating mb-3 js-datepicker',
  238.                 ],
  239.                 'constraints' => [
  240.                     new NotBlank([
  241.                         'message' => 'Vyberte přibližné datum doručení',
  242.                     ]),
  243.                 ],
  244.                 'label' => 'Delivery date',
  245.                 'widget' => 'single_text',
  246.                 'html5' => false,
  247.                 'mapped' => false,
  248.                 'format' => 'dd.mm.yyyy',
  249.             ])
  250.             ->add('code'TextType::class, [
  251.                 'label' => 'Sales code',
  252.                 'row_attr' => [
  253.                     'class' => 'form-floating mb-3',
  254.                 ],
  255.                 'required' => false,
  256.             ])
  257.             ->add('terms'CheckboxType::class, [
  258.                 'mapped' => false,
  259.                 'constraints' => [
  260.                     new IsTrue([
  261.                         'message' => 'Pro dokončení objednávky musíte souhlasit s podmínkami.',
  262.                     ]),
  263.                 ],
  264.                 'required' => true,
  265.                 'label' => 'Souhlasím s <a href="/general-terms-and-conditions">obchodními podmínkami</a> této služby.',
  266.                 'label_html' => true,
  267.             ])
  268.             ->add('template'EntityType::class, [
  269.                 'class' => Template::class,
  270.                 'choice_label' => 'name',
  271.                 'choice_value' => 'path',
  272.                 'mapped' => false,
  273.                 'required' => true,
  274.             ])
  275.             ->add('deliveryAddressCheckbox'CheckboxType::class, [
  276.                 'mapped' => false,
  277.                 'label' => 'Fakturační údaje se shodují s doručovacími',
  278.                 'label_html' => true,
  279.                 'required' => false,
  280.             ])
  281.             ->add('price'NumberType::class, [
  282.                 'row_attr' => [
  283.                     'class' => 'form-floating mb-3',
  284.                 ],
  285.                 'label' => 'Koncová částka',
  286.                 'required' => false,
  287.             ])
  288.             ->add('orderButton'SubmitType::class, [
  289.                 'label' => 'Objednat'
  290.             ])
  291.         ;
  292.     }
  293.     public function configureOptions(OptionsResolver $resolver): void
  294.     {
  295.         $resolver->setDefaults([
  296.             'data_class' => Order::class,
  297.             // enable/disable CSRF protection for this form
  298.             'csrf_protection' => true,
  299.             // the name of the hidden HTML field that stores the token
  300.             'csrf_field_name' => '_token',
  301.             // an arbitrary string used to generate the value of the token
  302.             // using a different string for each form improves its security
  303.             'csrf_token_id'   => 'task_item',
  304.         ]);
  305.     }
  306. }