Reputation: 1055
I need help. I've created view, where I'm creating multiple forms for one type of object. Now i want to save the forms, all with one button and then persist those objects to database.
Here is the controller:
/**
* @Route("/project/{project_id}/string/{id}/edit/", name="StringEdit")
* @Template()
*/
public function editAction($project_id, $id, Request $request)
{
$string = $this->getDoctrine()->getRepository('DomestosTranslatingBundle:String')->find($id);
$translations = $this->getDoctrine()->getRepository('DomestosTranslatingBundle:Translation')->findByString($string);
//$form = $this->createForm(new TranslationType(), $translation);
//$form->handleRequest($request);
$forms = array();
foreach($translations as $translation){
$form = $this->createForm(new TranslationType, $translation);
$form = $form->createView();
$forms[] = $form;
}
return $this->render('DomestosTranslatingBundle:String:edit.html.twig', array(
'forms' => $forms,
'string' => $string,
));
}
And the view:
{% extends "::base.html.twig" %}
{% block title %}Edit translations{% endblock %}
{% block body %}
Code: {{string.code}}
<p>
<table>
{% for keylang,lang in string.project.lang %}
{% for key,form in forms %}
{% if key == keylang %}
<tr>
<td>{{lang.title}}</td>
<td>{{form_widget(form.text)}}</td>
</tr>
{% endif %}
{% endfor %}
{% endfor %}
</table>
<p>
{% endblock %}
Upvotes: 1
Views: 6169
Reputation: 160833
No, you can't do this. Only one form could be submitted at one time.
Instead of using an array of forms, you could create one form and Embed a Collection of Forms.
Upvotes: 5