src/Form/USR_ajo.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use Symfony\Component\Form\AbstractType;
  4. use Symfony\Component\Form\FormBuilderInterface;
  5. use Symfony\Component\Form\FormEvent;
  6. use Symfony\Component\Form\FormEvents;
  7. use Symfony\Component\OptionsResolver\OptionsResolver;
  8. use Symfony\Component\Form\Extension\Core\Type\TextType;
  9. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  10. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  11. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  12. use App\Form\DataTransformer\CATTransformer;
  13. use App\Entity\usr;
  14. class USR_ajo extends AbstractType
  15. {
  16.     private $transformer;
  17.     public function __construct(CATTransformer $transformer)
  18.     {
  19.         $this->transformer $transformer;
  20.     }    
  21.     
  22.     public function buildForm(FormBuilderInterface $builder, array $options)
  23.     {
  24.         $builder
  25.             ->add('usrnom',
  26.                 TextType::class, 
  27.                 array( 
  28.                     'label'  => 'Nom *',
  29.                     'required'  => true,
  30.                     'attr'=>array('maxlength'=>'50')
  31.                 )
  32.             )
  33.             ->add('usrpre',
  34.                 TextType::class, 
  35.                 array( 
  36.                     'label'  => 'PrĂ©nom *',
  37.                     'required'  => true,
  38.                     'attr'=>array('maxlength'=>'30')
  39.                 )
  40.             )
  41.             ->add('catid',
  42.                   ChoiceType::class,
  43.                 array(
  44.                     'label'=>"Type de structure *",
  45.                     'required'  => true,
  46.                     'multiple'  => false,
  47.                     'expanded'  => false,
  48.                     'choices'=>$options['listCAT'],
  49.                 )
  50.             )   
  51.             ->add('usrorg',
  52.                   TextType::class,
  53.                 array( 
  54.                     'label'  => 'Structure *',
  55.                     'required'  => true,
  56.                     'attr'=>array('maxlength'=>'100')
  57.                 )
  58.             )
  59.             ->add('username',
  60.                   TextType::class,
  61.                 array( 
  62.                     'label'  => 'Identifiant (login) *',
  63.                     'required'  => true,
  64.                     'attr'=>array('maxlength'=>'20')
  65.                 )
  66.             )
  67.             ->add('usrpwdajo',
  68.                   PasswordType::class,
  69.                 array( 
  70.                     'label'  => 'Mot de passe *',
  71.                     'required'  => true,
  72.                     'attr'=>array('maxlength'=>'40'),
  73.                     'always_empty'  => true,
  74.                     'trim'  => true
  75.                 )
  76.             )
  77.             ->add('usrpwdconf',
  78.                   PasswordType::class,
  79.                 array( 
  80.                     'label'  => 'Confirmation *',
  81.                     'required'  => true,
  82.                     'attr'=>array('maxlength'=>'40'),
  83.                     'always_empty'  => true,
  84.                     'trim'  => true
  85.                 )
  86.             )
  87.             ->add('usremail',
  88.                   TextType::class,
  89.                 array( 
  90.                     'label'  => 'E-mail *',
  91.                     'required'  => true,
  92.                     'attr'=>array('maxlength'=>'128')
  93.                 )
  94.             )
  95.             ->add('usrcodpos',
  96.                   TextType::class,
  97.                 array( 
  98.                     'label'  => 'Code postal *',
  99.                     'required'  => true,
  100.                     'attr'=>array('maxlength'=>'5')
  101.                 )
  102.             )
  103.               ->add('usracccgu',
  104.                   HiddenType::class,
  105.                   array(
  106.                       'label'=>false
  107.                       'required'=>true
  108.                 )
  109.             )    
  110.         ;
  111.         
  112.         $builder->get('catid')->addModelTransformer($this->transformer); 
  113.         $builder->addEventListener(FormEvents::PRE_SET_DATA, array($this'onPreSetData'));
  114.     }
  115.     
  116.     function onPreSetData(FormEvent $event
  117.     {
  118.         $data $event->getData();
  119.         $form $event->getForm();
  120.     }
  121.     
  122.     public function configureOptions(OptionsResolver $resolver)
  123.     {
  124.         $resolver->setDefaults(
  125.             array(
  126.                 'data_class' => usr::class,
  127.                 'listCAT' => null,
  128.                 
  129.                 'csrf_protection' => true,
  130.                 'csrf_field_name' => '_token',
  131.                 'csrf_token_id' => 'usrajogarg;d44d'            // a unique key to help generate the secret token
  132.             )
  133.         );
  134.     }
  135.     
  136. }