1

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 %}

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.