Fieldset parameter is retrieved but is null

Hi everyone,
I have created my form wich contains fieldset. I retrieved my form parameter in my fieldset and I have to use it to add where clause to populate my select Element.
Unfortunately my parameter is null sometimes. I post here my code for appreciation.

My RapportEffetForm below

<?php

/**
    * @module     Commun
    * @subpackage Form\Admin
    * @author     Samuel NANGUI <nanguisamuel@gmail.com>
    * @copyright  Copyright (c) 2021 Nslabs
    */

namespace Commun\Form\Modules\Application;

use Commun\Form\Modules\Application\Fieldset\RapportEffetFieldset;


use Commun\Form\CommunForm;

class RapportEffetForm extends CommunForm 
{
     
        
    public function init() { 
        $myFieldset = $this->getFormFactory()->getFormElementManager()->get(RapportEffetFieldset::class, ['params' => $this->params]);        
        $this->setName('RapportEffetForm');
        $this->setAttribute('class', 'form-saisie');
        //$this->addFieldset(RapportEffetFieldset::class,['use_as_base_fieldset' => true]);
        $this->addFieldsetWithParameters($myFieldset,['use_as_base_fieldset' => true]);
        $this->addSubmitButton('next', 'Poursuivre', 'next', 'btn btn-vert w-100');        
        $this->addSubmitButton('previous', 'Retour', 'previous', 'btn btn-rouge w-100');
    }  
  
}

My RapportEffetFieldset here :

<?php

/**
    * @module     Commun
    * @subpackage Form\Admin
    * @author     Samuel NANGUI <nanguisamuel@gmail.com>
    * @copyright  Copyright (c) 2020 Nslabs
    */

namespace Commun\Form\Modules\Application\Fieldset;

use Commun\Model\Entity\Supervision;
use Laminas\InputFilter\InputFilterProviderInterface;
use Laminas\Hydrator\ReflectionHydrator;

use Commun\Form\Modules\Application\Fieldset\EffetRapportFieldset;
use Commun\Form\CommunFormFieldset;


class RapportEffetFieldset extends CommunFormFieldset implements InputFilterProviderInterface
{
        
    
    private $mapper;
    private $params;
       
    public function __construct($mappers=[],$params=[], $options = [])
    {                  
        $this->mapper = $mappers;
        $this->params = $params;                       
        parent::__construct($this->mapper,'RapportEffetForm',$options);           
        $this->setHydrator(new ReflectionHydrator());
        $this->setObject(new Supervision());
        $this->setLabel('RapportEffetFieldset');          
        
    }
    
    
    public function init() {   
        
        parent::init();           
        $myFieldset = $this->getFormFactory()->getFormElementManager()->get(EffetRapportFieldset::class, ['params' => $this->params]);        
        $this->addCollection('effets','', get_class(new $myFieldset()),1,[],'__index__',FALSE,FALSE);  
        $optionsNotation = $this->mapper['notations']->getOptions('idRefNotation','libelle','Sélectionner',null,['ordre']); 
        $this->addSelect('notationEffetPresent', 'Notation du présent rapport',$optionsNotation,['class' => 'form-control'],'champ-requis'); 
        $this->addSelect('notationEffetPrecedent', 'Notation du rapport précédent',$optionsNotation,['class' => 'form-control champ-affiche', 'placeholder' => 'Choisir']); 
        $this->addTextarea('JustifNotationEffet', 'Justification', NULL, ['class' => 'form-control','rows' => 5]);       
        
    }
    
        
    /**
     * @return array
     */
    public function getInputFilterSpecification()
    {
        return [
            
        ];
    }
}

My RapportEffetFieldsetFactory :

<?php

/**
    * @module     Commun
    * @subpackage Form
    * @author     Samuel NANGUI <nanguisamuel@gmail.com>
    * @copyright  Copyright (c) 2020 Nslabs
    */

namespace Commun\Factory\Form\Fieldset;


use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Commun\Form\Modules\Application\Fieldset\RapportEffetFieldset;

class RapportEffetFieldsetFactory implements FactoryInterface
{
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {         
        $params = $options['params'] ?? [];
        unset($options['params']);        
        $mappers = ['notations' => $container->get('TREFNOTATION')];
        return new RapportEffetFieldset($mappers,$params,$options);
        
    }
}

My EffetRapportFieldset :

<?php

/**
    * @module     Commun
    * @subpackage Form\Admin
    * @author     Samuel NANGUI <nanguisamuel@gmail.com>
    * @copyright  Copyright (c) 2020 Nslabs
    */

namespace Commun\Form\Modules\Application\Fieldset;

use Commun\Model\Entity\EffetProjet;
use Laminas\InputFilter\InputFilterProviderInterface;
use Laminas\Hydrator\ReflectionHydrator;

use Laminas\Filter\StripTags;
use Laminas\Filter\StringTrim;

use Commun\Form\CommunFormFieldset;


class EffetRapportFieldset extends CommunFormFieldset implements InputFilterProviderInterface
{
        
    
    private $mapper;
    private $inputFilter;   
    private $params;
       
    public function __construct($mappers=[],$params=[], $options = [])
    {        
        $this->mapper = $mappers;
        $this->params = $params;        
        parent::__construct($this->mapper,'EffetRapportForm',$options);           
        $this->setHydrator(new ReflectionHydrator());
        $this->setObject(new EffetProjet());
        //$this->setLabel('Nouvel effet');        
        
    }
    
    
    public function init() {       
        parent::init(); 
        $idProjet = $this->params['id'];  // I retrieve my param here like this. But I get this warning <<Notice: Undefined index: id in EffetRapportFieldset.php on line 45>>
        $optionsEffetCadreLogique = $this->mapper['effetProjet']->getOptions('idEffetProjet','libelleEffet','Sélectionner',['idProjet' => $idProjet ],['libelleEffet']);                                 
        $this->addSelect('idEffetProjet', 'Intitule de l\'effet',$optionsEffetCadreLogique,['class' => 'form-control champ-affiche'],'champ-requis'); 
        $this->addText('valeurReference','Valeur de référence (a)',NULL,['class' => 'form-control champ_decimal champ-affiche'],'champ-requis');
        $this->addText('valeurRecente','Valeur la plus récente (b)',NULL,['class' => 'form-control champ_decimal'],'champ-requis');
        $this->addText('valeurCible','Cible finale (c)',NULL,['class' => 'form-control champ_decimal champ-calcule'],'champ-requis');
        $this->addText('progresRealisation','Progrès vers la réalisation de la cible (% de réalisation) (d=b/c)',NULL,['class' => 'form-control champ_decimal champ-affiche'],'champ-requis');
        $this->addTextarea('evaluation', 'Évaluation', NULL, ['class' => 'form-control','rows' => 3]);               
    }
    
        
    /**
     * @return array
     */
    public function getInputFilterSpecification()
    {
        return [
            
        ];       
    }
}

My EffetRapportFieldsetFactory :

<?php

/**
    * @module     Commun
    * @subpackage Form
    * @author     Samuel NANGUI <nanguisamuel@gmail.com>
    * @copyright  Copyright (c) 2020 Nslabs
    */

namespace Commun\Factory\Form\Fieldset;


use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Commun\Form\Modules\Application\Fieldset\EffetRapportFieldset;

class EffetRapportFieldsetFactory implements FactoryInterface
{
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {                        
        $mappers = ['effetProjet' => $container->get('TEFFETPROJET')];
        return new EffetRapportFieldset($mappers,[],$options);
        
    }
}

My RapportEffetForm instantiation in my controller :

$rapportEffetForm = $this->formManager->get(\Commun\Form\Modules\Application\RapportEffetForm::class,['id' => $id]);

To @froschdesign , I would like to say I would follow your advice about removing the mappers in my form constructor, but for now I would like to get my option array for my select element dynamically but my $idProjet in my fieldset return null.

Any advice or help please ?

Uff, this is confusion:

  • CommunForm?
  • CommunFormFieldset?
  • RapportEffetFieldset vs. EffetRapportFieldset

The property $params is missing in RapportEffectForm and in EffectRapportFieldsetFactory the parameters always passed as empty array to the fieldset. It looks like something is missing here.

CommunForm is a generic form class which all form extend but I really do not use it except for creating submit input.
CommunFieldset is my generic fieldset that all fieldsets extend.

RapportEffetFieldset and EffortRapportFieldset are different. Maybe I need to rename them correctly but everything is OK except my parameter.
In EffortRapportFieldsetFactory, how to correctly set my params?

Compare the factories: RapportEffetFieldsetFactory vs. EffetRapportFieldsetFactory
The part for the parameters is missing in EffetRapportFieldsetFactory.

I suggest to use a debugger to check the creation of the fieldset and the way of the parameters array.

That’s my question. How can I do it correctly? I tried with options parameters but I get null value

You must add the same code for handling $params from the class RapportEffetFieldsetFactory to EffetRapportFieldsetFactory.
If you want to have access to the parameters in EffetRapportFieldset then it must be passed.

(Unfortunately, I cannot check the code myself, as not everything is shown here. So it is realistic that more needs to be done.)

OK. I will try and get back to you very soon.

Hello @froschdesign , I made some changes :
My RapportEffetForm :

<?php

/**
    * @module     Commun
    * @subpackage Form\Admin
    * @author     Samuel NANGUI <nanguisamuel@gmail.com>
    * @copyright  Copyright (c) 2021 Nslabs
    */

namespace Commun\Form\Modules\Application;

use Commun\Form\Modules\Application\Fieldset\RapportEffetFieldset;


use Commun\Form\CommunForm;

class RapportEffetForm extends CommunForm 
{
     
    private $parameters;
    public function __construct($params)
    {        
        $this->parameters=$params;
        parent::__construct('RapportEffetForm',$this->parameters,[]);                   
    }
        
    public function init() {           
        $myFieldset = $this->getFormFactory()->getFormElementManager()->get(RapportEffetFieldset::class, ['params' => $this->parameters]);        
        $this->setName('RapportEffetForm');
        $this->setAttribute('class', 'form-saisie');
        //$this->addFieldset(RapportEffetFieldset::class,['use_as_base_fieldset' => true]);
        $this->addFieldsetWithParameters($myFieldset,['use_as_base_fieldset' => true]);
        $this->addSubmitButton('next', 'Poursuivre', 'next', 'btn btn-vert w-100');        
        $this->addSubmitButton('previous', 'Retour', 'previous', 'btn btn-rouge w-100');
    }  
  
}

My RapportEffetFormFactory :

<?php

/**
    * @module     Commun
    * @subpackage Form
    * @author     Samuel NANGUI <nanguisamuel@gmail.com>
    * @copyright  Copyright (c) 2020 Nslabs
    */

namespace Commun\Factory\Form;


use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Commun\Form\Modules\Application\RapportEffetForm;

class RapportEffetFormFactory implements FactoryInterface
{
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {                 
        $params = $options['id'] ?? [];
        unset($options['id']);        
        return new RapportEffetForm($params);
    }
}

My RapportEffetFieldset :

<?php

/**
    * @module     Commun
    * @subpackage Form\Admin
    * @author     Samuel NANGUI <nanguisamuel@gmail.com>
    * @copyright  Copyright (c) 2020 Nslabs
    */

namespace Commun\Form\Modules\Application\Fieldset;

use Commun\Model\Entity\Supervision;
use Laminas\InputFilter\InputFilterProviderInterface;
use Laminas\Hydrator\ReflectionHydrator;

use Commun\Form\Modules\Application\Fieldset\EffetRapportFieldset;
use Commun\Form\CommunFormFieldset;


class RapportEffetFieldset extends CommunFormFieldset implements InputFilterProviderInterface
{
        
    
    private $mapper;
    private $params;
       
    public function __construct($mappers=[],$params=[], $options = [])
    {            
        
        $this->mapper = $mappers;
        $this->params = $params;                       
        parent::__construct($this->mapper,'RapportEffetForm',$options);           
        $this->setHydrator(new ReflectionHydrator());
        $this->setObject(new Supervision());
        $this->setLabel('RapportEffetFieldset');                  
    }
    
    
    public function init() {           
        parent::init();           
        $myFieldset = $this->getFormFactory()->getFormElementManager()->get(EffetRapportFieldset::class, ['params' => $this->params]);        
        $this->addCollection('effets','', get_class(new $myFieldset()),1,[],'__index__',FALSE,FALSE);  
        $optionsNotation = $this->mapper['notations']->getOptions('idRefNotation','libelle','Sélectionner',null,['ordre']); 
        $this->addSelect('notationEffetPresent', 'Notation du présent rapport',$optionsNotation,['class' => 'form-control'],'champ-requis'); 
        $this->addSelect('notationEffetPrecedent', 'Notation du rapport précédent',$optionsNotation,['class' => 'form-control champ-affiche', 'placeholder' => 'Choisir']); 
        $this->addTextarea('JustifNotationEffet', 'Justification', NULL, ['class' => 'form-control','rows' => 5]);       
        
    }
    
        
    /**
     * @return array
     */
    public function getInputFilterSpecification()
    {
        return [
            
        ];
    }
}

My RapportEffetFieldsetFactory :

<?php

/**
    * @module     Commun
    * @subpackage Form
    * @author     Samuel NANGUI <nanguisamuel@gmail.com>
    * @copyright  Copyright (c) 2020 Nslabs
    */

namespace Commun\Factory\Form\Fieldset;


use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Commun\Form\Modules\Application\Fieldset\RapportEffetFieldset;

class RapportEffetFieldsetFactory implements FactoryInterface
{
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {                 
        $params = $options['params'] ?? [];
        unset($options['params']);        
        $mappers = ['notations' => $container->get('TREFNOTATION')];
        return new RapportEffetFieldset($mappers,$params,$options);
        
    }
}

My EffetRapportFieldset :

<?php

/**
    * @module     Commun
    * @subpackage Form\Admin
    * @author     Samuel NANGUI <nanguisamuel@gmail.com>
    * @copyright  Copyright (c) 2020 Nslabs
    */

namespace Commun\Form\Modules\Application\Fieldset;

use Commun\Model\Entity\EffetProjet;
use Laminas\InputFilter\InputFilterProviderInterface;
use Laminas\Hydrator\ReflectionHydrator;

use Laminas\Filter\StripTags;
use Laminas\Filter\StringTrim;

use Commun\Form\CommunFormFieldset;


class EffetRapportFieldset extends CommunFormFieldset implements InputFilterProviderInterface
{
        
    
    private $mapper;
    private $inputFilter;   
    private $params;
       
    public function __construct($mappers=[],$params=[], $options = [])
    {        
        $this->mapper = $mappers;
        $this->params = $params;        
        parent::__construct($this->mapper,'EffetRapportForm',$options);           
        $this->setHydrator(new ReflectionHydrator());
        $this->setObject(new EffetProjet());          
        
    }
    
    
    public function init() {       
        parent::init();     
        var_dump($this->params);
        //die;
        $idProjet = $this->params['id'];  // I retrieve my param here like this. But I get this warning <<Notice: Undefined index: id in EffetRapportFieldset.php on line 45>>
        $optionsEffetCadreLogique = $this->mapper['effetProjet']->getOptions('idEffetProjet','libelleEffet','Sélectionner',['idProjet' => $idProjet],['libelleEffet']);                                 
        $this->addSelect('idEffetProjet', 'Intitule de l\'effet',$optionsEffetCadreLogique,['class' => 'form-control champ-affiche'],'champ-requis'); 
        $this->addText('valeurReference','Valeur de référence (a)',NULL,['class' => 'form-control champ_decimal champ-affiche'],'champ-requis');
        $this->addText('valeurRecente','Valeur la plus récente (b)',NULL,['class' => 'form-control champ_decimal'],'champ-requis');
        $this->addText('valeurCible','Cible finale (c)',NULL,['class' => 'form-control champ_decimal champ-calcule'],'champ-requis');
        $this->addText('progresRealisation','Progrès vers la réalisation de la cible (% de réalisation) (d=b/c)',NULL,['class' => 'form-control champ_decimal champ-affiche'],'champ-requis');
        $this->addTextarea('evaluation', 'Évaluation', NULL, ['class' => 'form-control','rows' => 3]);               
    }
    
        
    /**
     * @return array
     */
    public function getInputFilterSpecification()
    {
        return [
            
        ];       
    }
}

My EffetRapportFieldsetFactory :

<?php

/**
    * @module     Commun
    * @subpackage Form
    * @author     Samuel NANGUI <nanguisamuel@gmail.com>
    * @copyright  Copyright (c) 2020 Nslabs
    */

namespace Commun\Factory\Form\Fieldset;


use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Commun\Form\Modules\Application\Fieldset\EffetRapportFieldset;

class EffetRapportFieldsetFactory implements FactoryInterface
{
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {           
        $params = $options['params'] ?? [];
        unset($options['params']);        
        $mappers = ['effetProjet' => $container->get('TEFFETPROJET')];
        return new EffetRapportFieldset($mappers,$params,$options);
        
    }
}

My CommunForm class here :

<?php

/**
    * @module     Commun
    * @subpackage Form
    * @author     Samuel NANGUI <nanguisamuel@gmail.com>
    * @copyright  Copyright (c) 2020 Nslabs
    */

namespace Commun\Form;

use Laminas\Form\Form;
use Laminas\Hydrator\ClassMethodsHydrator;
use Laminas\InputFilter\InputFilter;
use Laminas\Form\Element\Select;
use Laminas\Form\Element\Hidden;

class CommunForm extends Form
{
    protected $mapper;
    public $params;
    public function __construct($formName=null,$params=[],$mapper=[]) {
        parent::__construct($formName);
        $this->mapper = $mapper;
        $this->params = $params;
        $this->setHydrator(new ClassMethodsHydrator(false));
        $this->setInputFilter(new InputFilter());
        $this->setAttribute('class', 'form-horizontal'); 
        //$this->setOption('params', $params);            
    }
    
    public function populateSelect(\Laminas\Form\Element\Select $selectName,$optionValues=[]){
        $selectName->setValueOptions($optionValues);
    }
    
    public function addFieldset($fieldset,$options=[]){        
        $this->add([
            'type' => $fieldset,
            'options' => $options,              
        ]);                
        
    }
    
    public function addFieldsetWithParameters($fieldset,$options=[]){        
        $this->add([
            'type' => get_class(new $fieldset()),
            'options' => $options,              
        ]);                
        
    }
    
    public function addSubmitButton($name,$label,$id='',$className=''){
        $this->add([
            'name' => $name,            
            'type'  => 'submit',            
            'attributes' => [
               'value' => $label,
               'id' =>  $id,
               'class' => $className,
           ]
        ]);        
    }
    
    
    public function addSelect($name,$label){
        $this->add([            
            'name' => $name,
            'type' => Select::class,
            'options' => [
                'label' => $label,
                'value_options' => [
                    '0' => 'French',
                    '1' => 'English',
                    '2' => 'Japanese',
                    '3' => 'Chinese',
                ],
            ],
        ]);
    }
    
    public function addFile($name,$label,$id='',$attributes=[],$labelClass=''){        
        $this->add([
            'name' => $name,
            'type' => 'file',
            'options' => [
                'label' => $label,   
                'id'    => $id,
                'label_attributes' => [
                    'class'  => $labelClass
                ],
            ],            
            'attributes' => $attributes,
        ]);
    }
    
    public function addHiddenElement($name,$attributes=[]){
        $this->add([
            'name' => $name,
            'type' => Hidden::class,            
            'attributes' => $attributes,
        ]);
    }
    
    public function addText($name,$label,$id='',$attributes=[],$labelClass=''){        
        $this->add([
            'name' => $name,
            'type' => 'text',
            'options' => [
                'label' => $label,   
                'id'    => $id,
                'label_attributes' => [
                    'class'  => $labelClass
                ],
            ],
            'attributes' => $attributes,
        ]);
    }
    
    
    
    
}

and my CommunFieldset :

<?php

/**
    * @module     Commun
    * @subpackage Form
    * @author     Samuel NANGUI <nanguisamuel@gmail.com>
    * @copyright  Copyright (c) 2021 Nslabs
    */

namespace Commun\Form;

use Laminas\Form\Element\Select;
use Laminas\Form\Fieldset;
use Laminas\Form\Element\Checkbox;
use Laminas\Form\Element\MultiCheckbox;
use Laminas\Form\Element\Button;
use Laminas\Form\Element\Hidden;


class CommunFormFieldset extends Fieldset
{        
 
    /**
     * Shortcut for adding an input type text element
     * @param string $name name of the item
     * @param string $label  label of the item
     * @param string $id unique HTML id of the item
     * @param array $attributes array of attributes to apply to the item     
     */
        
    //public $additionnalParams;
    private $mapper;
    
    public function __construct($mapper=[],$name=null,$options = []) {    
        //$this->additionnalParams = $options;
        $this->mapper = $mapper;            
        parent::__construct($name, $options);          
    }
    
    
    public function init(){        
        parent::init();
    }
        
    /**
     * Shortcut for adding an input type text element
     * @param string $name name of the item
     * @param string $label  label of the item
     * @param string $id unique HTML id of the item
     * @param array $attributes array of attributes to apply to the item  
     * @param string $labelClass label class(espacially for required item)   
     */
    
    public function addHiddenElement($name,$attributes=[]){
        $this->add([
            'name' => $name,
            'type' => Hidden::class,            
            'attributes' => $attributes,
        ]);
    }
    
    public function addText($name,$label,$id='',$attributes=[],$labelClass=''){        
        $this->add([
            'name' => $name,
            'type' => 'text',
            'options' => [
                'label' => $label,   
                'id'    => $id,
                'label_attributes' => [
                    'class'  => $labelClass
                ],
            ],
            'attributes' => $attributes,
        ]);
    }
    
    
    /**
     * Shortcut for adding an input type text element
     * @param string $name name of the item
     * @param string $label  label of the item
     * @param string $id unique HTML id of the item
     * @param array $attributes array of attributes to apply to the item  
     * @param string $labelClass label class(espacially for required item)   
     */
    
    public function addFile($name,$label,$id='',$attributes=[],$labelClass=''){        
        $this->add([
            'name' => $name,
            'type' => 'file',
            'options' => [
                'label' => $label,   
                'id'    => $id,
                'label_attributes' => [
                    'class'  => $labelClass
                ],
            ],            
            'attributes' => $attributes,
        ]);
    }
    
    public function addTextarea($name,$label,$id='',$attributes=[],$labelClass=''){        
        $this->add([
            'name' => $name,
            'type' => 'textarea',
            'options' => [
                'label' => $label,   
                'id'    => $id,
                'label_attributes' => [
                    'class'  => $labelClass
                ],                
            ],
            'attributes' => $attributes,
        ]);
    }
    
    /**
     * Shortcut for adding a select list type element
     * @param string $name name of the select item
     * @param string $label  label of the select item
     * @param array $valueOptions array values to populate the Select with
     * @param array $attributes array of attributes to apply to the Select item     
     * @param string $labelClass label class(espacially for required item)
     */
    
    public function addSelect($name,$label,$valueOptions=[],$attributes=[],$labelClass=''){ 
        $this->add([            
            'name' => $name,
            'type' => Select::class,            
            'options' => [
                'label' => $label,
                'value_options' => $valueOptions,
                'label_attributes' => [
                    'class'  => $labelClass
                ],
            ],
            'attributes' => $attributes,
        ]);
    }    
    
    public function addSelectFromTable($name,$label,$type,$attributes=[],$labelClass=''){ 
        $this->add([            
            'name' => $name,              
            'type' => get_class($type) ,            
            'options' => [
                'label' => $label,  
                'label_attributes' => [
                    'class'  => $labelClass
                ],
            ],
            //'label_attributes' => ['class'  => $labelClass],
            'attributes' => $attributes,
        ]);        
    }
    
    /**
     * Shortcut for adding a select list type element
     * @param string $name name of the select item
     * @param string $label  label of the select item
     * @param string $id id of the select item
     * @param string $checkedValue value of checked item.    
     * @param string $unCheckedValue value of unchecked item.    
     * @param array $attributes attribute array.    
     * @param string $labelClass label class(espacially for required item)   
     */
    
    public function addCheckbox($name,$label,$id='',$checkedValue='',$unCheckedValue='',$attributes=[],$labelClass=''){ 
        $this->setLabelAttributes(['class' => $labelClass]);
        $this->add([
            'name' => $name,
            'type' => Checkbox::class,
            'options' => [
                'label' => $label,   
                'id'    => $id,
                'use_hidden_element' => true,
                'checked_value' => $checkedValue,
                'unchecked_value' => $unCheckedValue,
                'label_attributes' => [
                    'class'  => $labelClass
                ],
            ],
            'attributes' => $attributes,
        ]);
    }
    
    
    
    public function addMultiCheckbox($name,$label,$id='',$valueOptions=[],$attributes=[],$labelClass=''){
        $this->add([
            'name' => $name,
            'type' => MultiCheckbox::class,            
            'options' => [
                'label' => $label,   
                'id'    => $id,
                'value_options' => $valueOptions,
                'label_attributes' => [
                    'class'  => $labelClass
                ],
            ],
            'attributes' => $attributes,
        ]);
    }
    
    public function addButton($name,$label,$attributes=[]){
        $this->add([
            'name' => $name,
            'type' => Button::class,              
            'options' => [
                'label' => $label,                
            ],
            'attributes' => $attributes,
        ]);
    }
        
    
    
    /**
     * Shortcut for adding a collection list type element
     * @param string $name name of the select item
     * @param string $label  label of the select item
     * @param string $targetElement name of the target fieldset
     * @param boolean $isObject indicate if the variable is an instance of a class or just a string     
     * @param int $count number of visible row
     * @param boolean $shouldCreateTemplate indicate if the html markup must be created
     * @param boolean $allowAdd indicate if new item can to addeds
     */
    
    
    private function getStringFromElement($element){
        if(gettype($element)==='object'){
            return get_class($element);
        }elseif(gettype($element)==='string'){
            return $element;
        }else{
            throw new \Exception('This type cannot be used with collection element');
        }
    }
    
    public function addCollection($name,$label, $targetElement,$count=2,$attributes=[],$templatePlaceholder='__index__',$shouldCreateTemplate=true,$allowAdd=true){         
        $this->add([
            'type' => \Laminas\Form\Element\Collection::class,
            'name' => $name,
            'options' => [
                'label' => $label,
                'count' => $count,
                'should_create_template' => $shouldCreateTemplate,
                'template_placeholder' => $templatePlaceholder,
                'allow_add' => $allowAdd,
                'target_element' => [
                    'type' =>  $this->getStringFromElement($targetElement),                                                         
                ],                 
            ],
            'attributes' => $attributes,                
        ]);
    }
    
}

When I make a var_dump in my init() function in EffetRapportFielset, I get this

And in the same page I get also this :

I need to say that when I do echo on $this->parameters on my RapportEffetForm I get my correct parameter value.

I do not know why for the first time, the value is good, and the (2nd time ??) is null. Do not know also why this value is shown twice.

Here are all my infos. Hope it helps you to also help me finding a solution :roll_eyes:

Is there someone to help please ? :anguished: :anguished: :anguished:

Problem solved by class my fieldset with
$this->getFormFactory()->getFormElementManager()->get(EffetsProjetSelect::class, ['params' => $this->params])

I searched further and I think that this problem may also apply to you:

The create method of Laminas\Form\Factory must be updated:

public function create($spec): ElementInterface
{
    $spec = $this->validateSpecification($spec, __METHOD__);
    $type = $spec['type'] ?? Element::class;

    $element = $this->getFormElementManager()->get(
        $type,
        $spec['options'] ?? null // this is missing!
    );

    // …
}

Thank you very much @froschdesign , This is what I used and I solved it partially but I’m facing to a new problem I posted 8m ago. See the link below please :