# Fieldset parameter is retrieved but is null

**URL:** https://discourse.laminas.dev/t/fieldset-parameter-is-retrieved-but-is-null/2594
**Category:** Components & MVC
**Tags:** laminas-form
**Created:** [November 12, 2021, 6:14pm UTC](https://discourse.laminas.dev/t/fieldset-parameter-is-retrieved-but-is-null/2594 "2021-11-12T18:14:10Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![ebuddy](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ebuddy/32/1536_2.png) [@ebuddy](https://discourse.laminas.dev/u/ebuddy)
#### Post date: [November 12, 2021, 6:14pm UTC](https://discourse.laminas.dev/t/fieldset-parameter-is-retrieved-but-is-null/2594/1 "2021-11-12T18:14:10Z")

</div>

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

```auto
<?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 :

```auto
<?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 :

```auto
<?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 :

```auto
<?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 :

```auto
<?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 ?

---

<div class="post-metadata">

### Author: ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)
#### Post date: [November 12, 2021, 10:01pm UTC](https://discourse.laminas.dev/t/fieldset-parameter-is-retrieved-but-is-null/2594/2 "2021-11-12T22:01:21Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ebuddy](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ebuddy/32/1536_2.png) [@ebuddy](https://discourse.laminas.dev/u/ebuddy)
#### Post date: [November 12, 2021, 10:17pm UTC](https://discourse.laminas.dev/t/fieldset-parameter-is-retrieved-but-is-null/2594/3 "2021-11-12T22:17:16Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)
#### Post date: [November 12, 2021, 10:37pm UTC](https://discourse.laminas.dev/t/fieldset-parameter-is-retrieved-but-is-null/2594/4 "2021-11-12T22:37:00Z")

</div>

> [@ebuddy](#):
>
> 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.

---

<div class="post-metadata">

### Author: ![ebuddy](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ebuddy/32/1536_2.png) [@ebuddy](https://discourse.laminas.dev/u/ebuddy)
#### Post date: [November 12, 2021, 10:53pm UTC](https://discourse.laminas.dev/t/fieldset-parameter-is-retrieved-but-is-null/2594/5 "2021-11-12T22:53:12Z")

</div>

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

---

<div class="post-metadata">

### Author: ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)
#### Post date: [November 13, 2021, 7:41am UTC](https://discourse.laminas.dev/t/fieldset-parameter-is-retrieved-but-is-null/2594/6 "2021-11-13T07:41:18Z")

</div>

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.)_

---

<div class="post-metadata">

### Author: ![ebuddy](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ebuddy/32/1536_2.png) [@ebuddy](https://discourse.laminas.dev/u/ebuddy)
#### Post date: [November 13, 2021, 3:39pm UTC](https://discourse.laminas.dev/t/fieldset-parameter-is-retrieved-but-is-null/2594/7 "2021-11-13T15:39:51Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ebuddy](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ebuddy/32/1536_2.png) [@ebuddy](https://discourse.laminas.dev/u/ebuddy)
#### Post date: [November 13, 2021, 6:02pm UTC](https://discourse.laminas.dev/t/fieldset-parameter-is-retrieved-but-is-null/2594/8 "2021-11-13T18:02:01Z")

</div>

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

```auto
<?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 :

```auto
<?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 :

```auto
<?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 :

```auto
<?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 :

```auto
<?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 :

```auto
<?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 :

```auto
<?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 :

```auto
<?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

 ![Error1](https://canada1.discourse-cdn.com/flex032/uploads/zendframework/original/2X/9/985330a599e49eed1057fbf94cc660066434fef6.png)

And in the same page I get also this :

 ![Error2](https://canada1.discourse-cdn.com/flex032/uploads/zendframework/original/2X/f/f7d5cc13772a0d2bd051cc4f81d57f382aad833e.png)

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 🙄

---

<div class="post-metadata">

### Author: ![ebuddy](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ebuddy/32/1536_2.png) [@ebuddy](https://discourse.laminas.dev/u/ebuddy)
#### Post date: [November 15, 2021, 9:46am UTC](https://discourse.laminas.dev/t/fieldset-parameter-is-retrieved-but-is-null/2594/9 "2021-11-15T09:46:48Z")

</div>

Is there someone to help please ? 😧 😧 😧

---

<div class="post-metadata">

### Author: ![ebuddy](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ebuddy/32/1536_2.png) [@ebuddy](https://discourse.laminas.dev/u/ebuddy)
#### Post date: [November 17, 2021, 8:17am UTC](https://discourse.laminas.dev/t/fieldset-parameter-is-retrieved-but-is-null/2594/10 "2021-11-17T08:17:25Z")

</div>

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

---

<div class="post-metadata">

### Author: ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)
#### Post date: [November 17, 2021, 8:26am UTC](https://discourse.laminas.dev/t/fieldset-parameter-is-retrieved-but-is-null/2594/11 "2021-11-17T08:26:08Z")

</div>

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

> <https://github.com/laminas/laminas-form/issues/3>
>
> How can you initialize if you don't have the options?
> 
> This is closely related… to https://github.com/zendframework/zend-form/issues/138
> 
> \### Code to reproduce the issue
> 
> 
> 
> \`\`\`php
> use Zend\\Form\\Factory;
> use Zend\\Form\\Element;
> use Zend\\Form\\FormElementManager\\FormElementManagerV3Polyfill;
> use Zend\\ServiceManager\\ServiceManager;
> 
> class MyElement extends Element
> {
> public function init()
> {
> echo "init\\n";
> }
> 
> public function setOptions($options)
> {
> echo "setOptions\\n"
> }
> }
> 
> // scenario 1, incorrect
> // same as calling $this-\>add() inside a fieldset
> $factory = new Factory();
> $factory-\>create(\[
> 'type' =\> MyElement::class,
> 'options' =\> \[
> 'my\_option' =\> true
> \]
> \]);
> 
> echo "\\n";
> 
> // scenario 2, correct
> $formElementManager = new FormElementManagerV3Polyfill(new ServiceManager());
> $countrySelect = $formElementManager-\>get(MyElement::class, \[
> 'my\_option' =\> true
> \]);
> \`\`\`
> 
> \### Expected results
> 
> setOptions
> init
> 
> setOptions
> init
> 
> \### Actual results
> 
> init
> setOptions
> 
> setOptions
> init
> 
> \### Workaround
> 
> There are several different workarounds:
> \- Don't use Zend\\Form\\Factory. This means don't use \`$this-\>add()\` in a fieldset. Write factories which initialize elements and fieldsets.
> \- Manually call -\>init() again on the element after it's been created
> \- Implement ElementPrepareAwareInterface instead of InitializableInterface (adds an unused dependency from Element to Fieldset)
> \- Apply the 1-line fix to Zend\\Form\\Factory:
> \`\`\`
> \- $element = $this-\>getFormElementManager()-\>get($type);
> + $element = $this-\>getFormElementManager()-\>get($type, $spec\['options'\] ?? \[\]);
> \`\`\`
> 
> \### Proper fix
> 
> I don't see a coherent solution which doesn't involve overhauling how stuff works. 
> 
> If you move towards constructor injection this would break many factories people wrote.
> 
> Zend\\ServiceManager\\Initializer\\InitializerInterface does not support passing options. If it did you could move the setOptions() logic to there with little BC break. 
> 
> (DelgatorFactoryInterface does support passing options but you'd have to register it for every element).
> 
> \---
> 
> Originally posted by @Erikvv at https://github.com/zendframework/zend-form/issues/221

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

```php
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!
    );

    // …
}

```

---

<div class="post-metadata">

### Author: ![ebuddy](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ebuddy/32/1536_2.png) [@ebuddy](https://discourse.laminas.dev/u/ebuddy)
#### Post date: [November 17, 2021, 8:28am UTC](https://discourse.laminas.dev/t/fieldset-parameter-is-retrieved-but-is-null/2594/12 "2021-11-17T08:28:58Z")

</div>

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 :

> [@Laminas fieldset unable to use custom select with where clause](https://discourse.laminas.dev/t/laminas-fieldset-unable-to-use-custom-select-with-where-clause/2601):
>
> I have a laminas form wich contains a fieldset. In this fieldset, I have a custom select Element wich is populate from database with a where clause depending on parameter passed to my fieldset. However, when I use my custom Select, I get this error message \<\<Argument 1 passed to Laminas\ServiceManager\ServiceManager::Laminas\ServiceManager{closure}() must be of the type string, object given, called in…\>\>. I post my code below : My fieldset here : \<?php /\*\* \* @module Commun \* @subp…
