Create array input field with form builder symfony2

对着背影说爱祢 提交于 2019-12-05 04:42:19

You can create an array of input fields using the 'collection'-field type.

Documentation about how to use it can be found here:

Collection documentation

If that isn't clear enough or you still have questions I will gladly help you with them.

As the previous answer states, use the collection type or a nested form, where each field corresponds to one entry of the array. And in cases where you can't/don't want to do that, you can do the following:

->add('attribute_0', 'text', array(
    'property_path' => 'attribute[0]',
))

Also you can ovveride field in TWIG. Example:

   {{ form_row(form[field_name],{ 'full_name':  'attribute[' ~ step ~ ']' })}} 

Where step is your index.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!