php - symfony2 display twice the fields of the form -


i have list of "hours" workers passed on mandates. admin can check them (checkbox)to add them bill, (but can adapt real hours)

so, have array of hour selected, in controler hours :

$hours = $repository->findby(array('id' => $tabhour)); 

so $hours countain more 1 hour, thought if creating form $hours, automaticly display fields more once..

foreach($hours $key => $test){      $billedhour[$key] = new billedhour();     $form[$key] = $this->container->get('form.factory')->create(new billmandateform(), $hour); }    

i tried this. it's not solved, cause if return collection of forms can't 'form' => $form->createview()so can't render forms...

try pack form views in array

$billedhours = array(); $forms = array(); foreach($hours $hour) {     $billedhours[] = new billedhour();     $forms[] = $this->container->get('form.factory')->create(new billmandateform(), $hour); } 

then, create array of rendered form views

$formstorender = array(); foreach($forms $form) {     $formstorender[] = $form->createview(); } 

then, pass array twig:

... 'forms' => $formstorender ... 

and in twig render each of form views array:

{% form in forms %}     {{ form_row(form.id) }} {# or form_widget(form) if want render whole instead of fields #} {% endfor %} 

i hope helps ;)


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -