puntotuning
puntotuning

Reputation: 54

Symfony2 - Reuse form type multiple times in a form

I am trying to make a form where a user can insert his curriculum vitae data. At the moment i have created an experience form type containing all the experience related fields. The problem is that the user has to be able to add or remove as many experiences as he likes clicking add or minus buttons. I can accomplish this with javascript, but it doesn't seem to be the best solution. Is there a way of accomplishing this with symfony2? Maybe with some kind of event listener that creates or removes a form type?

Upvotes: 0

Views: 944

Answers (2)

Emii Khaos
Emii Khaos

Reputation: 10085

An own experience form type is good. Then you need to implement this form type as a collection in your parent form. For adding/removing an experience in the rendered output javascript/jQuery is still needed. But only for adding the <form> prototype.

Take a look at this exciting cookbook article about collection in forms

Upvotes: 1

Wouter J
Wouter J

Reputation: 41934

It should be done with JavaScript, as a server side script language (php) can't run without refreshing the page.

On how to do this with Symfony, see: http://symfony.com/doc/current/cookbook/form/form_collections.html

Upvotes: 2

Related Questions