0
votes

I have made a form which embedded forms to add new records in a one-to-many relationship with ajax, my question is, where do I edit the template for the embedded form? because I would assume this would be in _form.php but it doesn't seem to use that template

Thanks in advance

2
in fact it does come from the same _form partial as the main form. Form elements in symfony by default render as a table row, so this might be what is causing your confusion. Could you please tell us what you're wanting to do. - xzyfer

2 Answers

0
votes

If your are adding fields by ajax you can do the response of the ajax with some template. For example if you have a mail field you could do:

public function executeAddMailForm($request)
{
    $this->forward404unless($request->isXmlHttpRequest());

    $mail = new MailForm();

    //action logic...

    return $this->renderPartial('addMail',array('form' => $form));
}

and make a _addMail template:

<div class="form-ajax-item">
    <div class="form-ajax-label">
        <?=$form['mail']->renderLabel()?>
    </div>
    <div class="form-ajax-field">
        <?=$form['mail']->render()?>
    </div>
</div>

This way you can do the ajax response using templates.

0
votes

In fact it does come from the same _form partial as the main form. Form elements in symfony by default render as a table row, so this might be what is causing your confusion. Could you please tell us what you're wanting to do.

There is documentation on how to do this and a very detailed example on the symfony website see here. It's pretty in depth and can look a bit daunting but I recommend you read through it and make sure you take the time to actually understand it.