I have five data entries from database, mapset` that I render in twig:
{{ form_start(form) }}
{% for item in mapset %}
<tr>
<td>{{ item.name }}</td>
<td>{{ form_widget(form.sets) }}</td>
<td>{{ form_widget(form.options) }}</td>
<td>{{ form_widget(form.buttonSet) }}</td>
<td>{{ form_widget(form.buttonItem) }}</td>
</tr>
{% endfor %}
{{ form_end(form) }}
This form should render a total of 20 inputs that would look like this:
name1 [] [] [] []
name2 [] [] [] []
name3 [] [] [] []
name4 [] [] [] []
name5 [] [] [] []
but my codes shows:
name1 [] [] [] []
name2
name3
name4
name5
I've read a lot about dynamic form and form collection but I don't get it.
{# src/AppBundle/Resources/views/Task/new.html.twig #}
{# ... #}
{{ form_start(form) }}
{# render the task's only field: description #}
{{ form_row(form.description) }}
<h3>Tags</h3>
<ul class="tags">
{# iterate over each existing tag and render its only field: name #}
{% for tag in form.tags %}
<li>{{ form_row(tag.name) }}</li>
{% endfor %}
</ul>
{{ form_end(form) }}
{# ... #}
http://symfony.com/doc/2.7/cookbook/form/form_collections.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.