AppleandPear
AppleandPear

Reputation: 51

Symfony 3 connect forms and entities together

I'm building company details form in Symfony 3.2. The Company entity have several text fields (like company name, address, website url, and so on...). Also I've created another entity, named Services (it's like categories) with relation ManyToMany - because one Company can have many services, and one service can have many Companies.

The services list I can set only in the EasyAdminBundle. On the user-side the 'company details form' should displaying only checkboxes with service names. I don't want to create form for users where they will be able to add new 'service' name. User can fill only text-fields with his Company details and select several checkboxes with the services where his Company will be displayed on the catalog.

My problem is that I completely don't know how to do it. At this moment I've successfully connected the 'user registration form' with the 'Company details form'. I'm still learning Symfony - this is my first project with this framework.

The source of this project is available on my BitBucket account

Upvotes: 0

Views: 901

Answers (1)

Maya Shah
Maya Shah

Reputation: 970

If you want to show checkboxes, use multiple and expanded property with EntityType field in your CompanyType form.

       $builder->add('services', EntityType::class, [
            'class'    => 'AppBundle\Entity\Services',
            'label'    => 'Services',                
            'multiple' => true,
            'expanded' => true
        ])

check http://symfony.com/doc/current/reference/forms/types/entity.html

Upvotes: 1

Related Questions