Dec
03
2009
18

Expanding forms with symfony 1.2 and Doctrine

I recently started learning how to use the forms system in symfony 1.2 and for the most part I was impressed with its simplicity and flexibility. Unfortunately I was thrown in the deep end somewhat when a project I was working on had a requirement for an “expanding” form – that is, one where a certain section of a form should be able to be repeated as many times as necessary to accommodate the user’s needs.

In the case of the project in question, the specific situation was an application form where the user could fill out any number of team members involved in their project. Each team member consisted of a name and a role, both free-form text fields. Team members were to be stored in the database, linked to the application in a one to many relationship.

Circumstances conspired that this must be achieved in a single form, so full of confidence in symfony’s design decisions regarding the forms system, a bit of light Googling revealed the answer – symfony’s embedded forms system. Great, so you just plonk in a few embedded forms and away you go, right? Wrong.

The good news is, I managed to find a solution that satisfied the requirements, eventually. The bad news is that it is not easy, elegant, or particularly reusable.

What follows is a loose guide to implementing such a system. Being a relative newcomer to symfony I cannot guarantee that this is the best way to do things, so tread with caution, and if you think of a better way to achieve the same outcome, please please let me know! Read on if you dare… (more…)

Powered by WordPress | Aeros Theme | TheBuckmaker.com