开发者

Symfony - Changing templates for embedded forms

开发者 https://www.devze.com 2023-02-15 16:57 出处:网络
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 woul

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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消