<?php
namespace App\Form;
use App\Validator\Constraints\AtLeastOneNotNull;
use Eckinox\TinymceBundle\Form\Type\TinymceType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Regex;
class ContactUsFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name', TextType::class, [
'label' => 'Jméno a příjmení',
'row_attr' => [
'class' => 'form-floating mb-3',
],
'required' => false,
])
->add('email', EmailType::class, [
'label' => 'Emailová adresa',
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new AtLeastOneNotNull(null, [
'fields' => ['email', 'phone'],
'message' => 'Email nebo telefonní číslo musí být vyplněno.'
])
],
'required' => false,
])
->add('phone', TextType::class, [
'row_attr' => [
'class' => 'form-floating mb-3',
],
'constraints' => [
new Regex([
'pattern' => '/^(\+?3[0-9]{1,2}\s?)?((\([0-9]{1,5}\))|[0-9]{1,5})\s?[0-9]{1,9}((\s|-)[0-9]{1,9})?$/',
'message' => 'Vyplňte platné telefonní číslo',
]),
new AtLeastOneNotNull(null, [
'fields' => ['email', 'phone'],
'message' => 'Email nebo telefonní číslo musí být vyplněno.'
])
],
'label' => 'Telefonní číslo',
'required' => false,
])
->add('message', TinymceType::class, [
'required' => true,
'row_attr' => [
'class' => 'form-floating mb-3',
],
'attr' => [
'toolbar' => 'undo redo | casechange blocks | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist checklist outdent indent | removeformat | a11ycheck'
],
'constraints' => [
new NotBlank([
'message' => 'Vyplňte text zprávy',
]),
],
'label' => 'Váš dotaz',
'mapped' => false,
])
->add('save', SubmitType::class, [
'label' => 'Odeslat zprávu',
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{}
}