Symfony2 Form, How do I customize?

2019-08-13 19:49发布

To render a form, within a .twig template I have:

{{ form_start(form) }}
{{ form_row(form.title) }}
{{ form_row(form.description) }}
{{ form_end(form) }}

I get

<form name="job" method="post" action="/myname/Job/create">

<div><label for="job_title" class="required">Title</label>
<input type="text" id="job_title" name="job[title]" /></div>

<div><label for="job_description" class="required">Description</label>
<input type="text" id="job_description" name="job[description]" /></div>
</form>

but I need to render it something like:

<form name="job" method="post" action="/myname/Job/create">

<div><label for="job_title" class="required">Title</label>
<input type="text" id="job_title" name="job[0][title]" /></div>

<div><label for="job_description" class="required">Description</label>
<input type="text" id="job_description" name="job[0][description]" /></div>
</form>

the point being to insert the index [0]. (This I need to apply a JS trick)

I looked at form_div_layout.html.twig, I understand that the rendering of a form is given by the lines under {%- block widget_attributes -%}, but I do not see how Symfony 2.7 assigns that piece of html to {{ full_name }}.

标签: forms symfony
0条回答
登录 后发表回答