Sense
Sense

Reputation: 1106

How to create a custom form in Symfony 2

I have three entities : Service, Group, Agent.

Service => oneToMany => Group => oneToMany => Agent

Each of these entities already have a form. By the way, I would like to create a custom mergeForm which will contains a select field Service to choose and a select field Groupe in order to merge some of these entities. The Symfony 2 official cookbook is under maintenance, so I would like to know the way to create the custom Form in which I will be able to choose a Service (from all existing services) and to choose a Group (from all existing groups)

Upvotes: 4

Views: 305

Answers (1)

Craige
Craige

Reputation: 2891

What you're looking for is probably entity field type. This will allow you to embed within the form a select field that points to the foreign entity. This is primarily useful for small collections.

When you start dealing with large collections, and find the need/desire to load entities with Javascript (e.g. The collection is to large to justify loading all on page-load), you'll have to look at Symfony2 Documentation: How to Embed a Collection of Forms.

It's also worth noting that there is a pull request slated for Symfony 2.2 that is supposed to make dealing with this type of form easier.

Upvotes: 1

Related Questions