<?php
namespace App\Form;
use App\Entity\User;
use App\Entity\Package;
use App\Entity\BusinessPackage;
use Symfony\Component\Form\AbstractType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Regex;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
class ContactFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name', TextType::class, [
'mapped' => false,
'label_attr' => ['class' => 'uk-form-label'],
'row_attr' => ['class' => 'uk-margin'],
'attr' => ['autocomplete' => 'name', 'class' => 'uk-input'],
'constraints' => [
new Regex([
'pattern' => "/^[a-zA-Z0-9\p{Greek},\ \.]+$/u",
'message' => 'Your name must contains only letters or .',
]),
new NotBlank([
'message' => 'Please enter your name',
]),
new Length([
'min' => 3,
'minMessage' => 'Your name should be at least {{ limit }} characters',
'max' => 50,
]),
],
])
->add('email', EmailType::class, [
'mapped' => false,
'label_attr' => ['class' => 'uk-form-label'],
'attr' => ['autocomplete' => 'email', 'class' => 'uk-input'],
'constraints' => [
new NotBlank([
'message' => 'Please enter your email',
]),
],
])
->add('phone', TelType::class, [
'mapped' => false,
'label_attr' => ['class' => 'uk-form-label'],
'row_attr' => ['class' => 'uk-margin'],
'attr' => ['autocomplete' => 'phone', 'class' => 'uk-input'],
'constraints' => [
new Length([
'minMessage' => 'Your telephone number should be at least {{ limit }} characters',
'max' => 50,
]),
new Regex([
'pattern' => "/^(\+)?[0-9]*$/",
'message' => 'Your telephone number is not a valid number',
]),
],
])
->add('instested', ChoiceType::class, [
'mapped' => false,
'label' => 'I am intrested in',
'label_attr' => ['class' => 'uk-form-label'],
'row_attr' => ['class' => 'uk-margin'],
'attr' => ['class' => 'uk-select'],
'data' => 'other',
'choices' => [
'Trainings' => 'trainings',
'Business Offer' => 'business-offer',
'Other' => 'other',
],
])
->add('message', TextareaType::class, [
'mapped' => false,
'label_attr' => ['class' => 'uk-form-label'],
'row_attr' => ['class' => 'uk-margin'],
'attr' => ['autocomplete' => 'message', 'class' => 'uk-textarea uk-height-small'],
'constraints' => [
new NotBlank([
'message' => 'Please enter your message',
]),
new Length([
'min' => 3,
'minMessage' => 'Your message should be at least {{ limit }} characters',
]),
],
])
->add('captcha', Recaptcha3Type::class, [
'constraints' => new Recaptcha3([
'message' => 'There were problems with your captcha. Please try again or contact with support and provide following code(s): {{ errorCodes }}'
]),
'action_name' => 'contact',
//'script_nonce_csp' => $nonceCSP,
])
->add('submit', SubmitType::class, [
'label' => 'Send',
'row_attr' => ['class' => 'uk-margin uk-text-center'],
'attr' => ['class' => 'uk-button uk-button-large uk-button-primary uk-border-pill'],
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}