<?php
namespace App\Form;
use App\Entity\Delegation;
use App\Entity\Partenaire;
use App\Entity\Gouvernorat;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
class PartenaireRegionalType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('email', EmailType::class, ['label' => 'inscription.part_reg.email', 'required' => true, 'constraints' => [
new NotBlank([
'message' => 'Ce champs est obligatoire',
]),
],], array('attr' => array('class' => 'form-control left-line')))
->add('username', TextType::class, ['label' => 'inscription.part_reg.username', 'required' => true, 'constraints' => [
new NotBlank([
'message' => 'Ce champs est obligatoire',
]),
],], array('attr' => array('class' => 'form-control left-line')))
->add('plainPassword', PasswordType::class, [
// instead of being set onto the object directly,
// this is read and encoded in the controller
'label' => 'inscription.part_reg.password',
'mapped' => false,
'attr' => ['autocomplete' => 'new-password', 'class' => 'form-style password1'],
'constraints' => [
new NotBlank([
'message' => 'Please enter a password',
]),
new Length([
'minMessage' => 'Your password should be at least {{ limit }} characters',
// max length allowed by Symfony for security reasons
'max' => 4096,
]),
],
])
->add('confirmpassword', PasswordType::class, [
// instead of being set onto the object directly,
// this is read and encoded in the controller
'label' => 'inscription.part_reg.confirm_pass',
'mapped' => false,
'attr' => ['autocomplete' => 'new-password', 'class' => 'form-style password2'],
'constraints' => [
new Length([
'minMessage' => 'Your password should be at least {{ limit }} characters',
// max length allowed by Symfony for security reasons
'max' => 4096,
]),
],
])
->add('nom', TextType::class, ['label' => 'inscription.part_reg.name'], array('attr' => array('class' => 'form-control left-line')))
->add('nombre_entreprise', TextType::class, [
'label' => 'inscription.part_reg.number',
// 'mapped' => false,
'attr'=> ['min' => 0, 'pattern'=>'[0-9]+', 'oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"],
])
->add('adresse', TextType::class, [
'label' => 'inscription.part_reg.adresse',
'mapped' => false
])
->add('gouvernorat', EntityType::class, array(
'class'=>Gouvernorat::class,
'label' => 'inscription.part_reg.gov',
'choice_label'=>'libelle',
'choice_translation_domain'=> true,
'multiple'=>false,
'mapped' => false,
))
->add('delegation', EntityType::class, array(
'class'=>Delegation::class,
'label' => 'inscription.part_reg.delegation',
'choice_label'=>'libelle',
'choice_translation_domain'=> true,
'multiple'=>false,
'mapped' => false,
))
->add('code_postale', TextType::class, [
'label' => 'inscription.part_reg.postal_code',
'mapped' => false,
'attr'=> ['min' => 0 ,'pattern' => '\d{4}', 'title' => 'Entrez exactement 4 chiffres', 'maxlength' => 4, 'oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"],
])
->add('tel', TextType::class, [
'label' => 'inscription.part_reg.tel',
'required' => true,
'attr'=> ['min' => 0, 'pattern'=>'\d{8}', 'maxlength' => 8, 'oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"],
'constraints' => [
new NotBlank([
'message' => 'Ce champs est obligatoire',
]),
],], array('attr' => array('class' => 'form-control left-line')))
->add('fax', TextType::class, ['label' => 'inscription.part_reg.fax',
'attr'=> ['min' => 0, 'pattern' => '\d{8}', 'maxlength' => 8, 'oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"],
])
->add('nom_prenom_president', TextType::class, ['label' => 'inscription.part_reg.president'])
->add('nom_prenom_secretaire_general', TextType::class, ['label' => 'inscription.part_reg.s_generale'])
->add('nom_prenom_responsable_UAF', TextType::class, ['label' => 'inscription.part_reg.resp_uaf'])
->add('cnsscnrps', ChoiceType::class, [
'label' => 'inscription.part_reg.CNSS/CNRPS',
'required' => false ,
'choices' => [
'CNSS' => 'CNSS',
'CNRPS' => 'CNRPS',
],
'placeholder' => 'inscription.part_reg.choose',
])
->add('code_cnss', TextType::class, ['label' => 'inscription.part_reg.Code_CNSS_Code_CNRPS'
, 'attr'=> [ 'pattern'=>'[0-9]+', 'oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"]
]) ->add('secteur', TextType::class, ['label' => 'inscription.part_reg.activity_sector'])
->add('branche', TextType::class, ['label' => 'inscription.part_reg.activity_branch'])
->add('enterprisePartenaires', CollectionType::class, array('entry_type' => EnterprisePartenaireType::class,
'allow_add' => true,
'allow_delete' => true,
'form_attr' => 'ok',
'label' => false,
'auto_initialize' => false,
'block_name' => null,
'compound' => true,
'by_reference' => false,
"row_attr" => ['class' => 'form_entreprise_partenaire_regional'], 'attr' => array('id' => 'entreprise_partenaire')))
->add('fileName', FileType::class, [
'label' => 'inscription.part_reg.choose_file',
'mapped' => false, // Cela signifie qu'il ne sera pas directement lié à une propriété de l'entité
'required' => false, // Définissez à false si le fichier est facultatif
])
->add('agreeTerms', CheckboxType::class, [
'label' => 'inscription.part_reg.terms',
'label_html' => true,
'mapped' => false,
'data_class' => null,
"row_attr" => ['class' => 'accepter_cond'], 'attr' => array('id' => ''),
'constraints' => [
new IsTrue([
'message' => 'Vous devez accepter nos conditions.',
]),
],
])
->add('Enregistrer', SubmitType::class, [
'label' => 'inscription.save',
'attr' => ['class' => 'save'],
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Partenaire::class,
]);
}
}