<?php
/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Enterprise License (PEL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PEL
*/
namespace App\Form;
use Pimcore\Localization\LocaleService;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
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\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
class ContactUsFormType extends AbstractType
{
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('subject', ChoiceType::class, [
'label' => 'Argomento della richiesta',
'required' => true,
'choices' => array_combine($this->subjects(),$this->subjects()),
'choice_translation_domain' => 'messages',
'attr' => ['class' => 'form-control col-sm-9']
])
->add('firstname', TextType::class, [
'label' => 'Nome',
'attr' => ['class' => 'form-control col-sm-3'],
'required' => true,
])
->add('lastname', TextType::class, [
'label' => 'Cognome',
'attr' => ['class' => 'form-control col-sm-3'],
'required' => true,
])
->add('email', EmailType::class, [
'label' => 'Email',
'attr' => ['class' => 'form-control col-sm-3'],
'required' => true,
])
->add('address', TextType::class, [
'label' => 'Indirizzo',
'attr' => ['class' => 'form-control col-sm-3'],
'required' => false,
])
->add('cap', TextType::class, [
'label' => 'CAP',
'attr' => ['class' => 'form-control col-sm-3'],
'required' => false,
])
->add('locality', TextType::class, [
'label' => 'Località',
'attr' => ['class' => 'form-control col-sm-3'],
'required' => false,
])
->add('province', ChoiceType::class, [
'label' => 'Provincia',
'required' => true,
'choices' => array_flip($this->italianRegions()),
'choice_translation_domain' => false,
'attr' => ['class' => 'form-control col-sm-3']
])
->add('phone', TextType::class, [
'label' => 'Telefono',
'attr' => ['class' => 'form-control col-sm-3'],
'required' => false,
])
->add('message', TextareaType::class, [
'label' => 'Richiesta',
'attr' => ['class' => 'form-control col-sm-9'],
'required' => true,
])
->add('consent', CheckboxType::class, [
'label' => 'Contsent',
'attr' => ['class' => 'custom-control-input mr-2'],
'required' => true,
])
->add('_target_path', HiddenType::class)
->add('captcha', Recaptcha3Type::class, [
'constraints' => new Recaptcha3(),
'action_name' => 'contactus',
'locale' => 'it',
])
->add('_submit', SubmitType::class, [
'label' => 'Invia',
'attr' => ['class' => 'btn c-button yellow']
]);
}
/**
* @inheritDoc
*/
public function getBlockPrefix()
{
// we need to set this to an empty string as we want _username as input name
// instead of login_form[_username] to work with the form authenticator out
// of the box
return '';
}
/**
* @inheritDoc
*/
public function configureOptions(OptionsResolver $resolver)
{
}
public function subjects(){
return $regions = [
'informazioni sui prodotti' => 'contatti.informazioni-sui-prodotti',
'stato degli ordini' => 'contatti.stato-degli-ordini',
'aspetti amministrativi' => 'contatti.aspetti-amministrativi',
'procedure di reso' => 'contatti.procedure-di-reso',
'altro' => 'contatti.altro'
];
}
public function italianRegions(){
return $regions = [
'abruzzo' => 'Abruzzo',
'basilicata' => 'Basilicata',
'calabria' => 'Calabria',
'campania' => 'Campania',
'emilia-romagna' => 'Emilia-Romagna',
'friuli-venezia-giulia' => 'Friuli-Venezia Giulia',
'lazio' => 'Lazio',
'liguria' => 'Liguria',
'lombardia' => 'Lombardia',
'marche' => 'Marche',
'molise' => 'Molise',
'piemonte' => 'Piemonte',
'puglia' => 'Puglia',
'sardegna' => 'Sardegna',
'sicilia' => 'Sicilia',
'toscana' => 'Toscana',
'trentino-alto' => 'Trentino-Alto Adige/Südtirol',
'umbria' => 'Umbria',
'valle' => 'Valle d\'Aosta/Vallée d\'Aoste',
'veneto' => 'Veneto',
'' => '',
];
}
}