Populate Select element in form

Hi everyone,
I would like to build a form with select elements and populate them with database entries.
How can I include many repositories (I have more than one select element) in my form ?
Is it good to pass the service manager (to access to all my repositories) in the constructor of my forms ?
Any advice or code snippet ?

Create separated form elements and you do not need to inject many repositories.
See also:

See my comment to the same topic here:

never inject the entire service manager in a class. If you do that, then you have a design fault from the start and you are on the best way to an anti-pattern. Your class should not even know that there is a dependency injection container. Give only what is necessary.

Thank you @froschdesign . Thank you so much !!!

Hello @froschdesign , I tried what you have said and it works. But in my controller, I get this error when I call myform->isvalid(). Here is the error message

File:

C:\wamp\www\school-online\vendor\laminas\laminas-validator\src\AbstractValidator.php:395

Message:

Argument 1 passed to Laminas\Validator\AbstractValidator::setTranslator() must be an instance of Laminas\Validator\Translator\TranslatorInterface or null, instance of Laminas\I18n\Translator\Translator given, called in C:\wamp\www\school-online\vendor\laminas\laminas-validator\src\ValidatorPluginManager.php on line 580

Please create a separate post for this topic because this post is marked as solved. Additionally, the new topic is then easier for others to find. Thanks in advance! :+1: