<p>I know I'm a bit late to this, but I think it's because your <code>{{ loop.index }}</code> is not <strong><a href="https://twig.symfony.com/doc/2.x/tags/for.html#the-loop-variable" rel="nofollow noreferrer">0-indexed</a></strong>, which is necessary for the array.  It should look like this:</p>

<p><code>&lt;input type="hidden" name="fields[selections][{{ loop.index0 }}][col1]" value="{{ item.qty }} x {{ item.description }}"&gt;</code></p>

<p>You also need an extra valueless <code>hidden</code> field above the loop to collect all the values into one array:</p>

<p><code>&lt;input type="hidden" name="fields[selections]" value=""&gt;</code></p>

<p>You can see a fuller example on how to format the HTML for all fields of all types on this <strong><a href="https://straightupcraft.com/articles/craft-cms-field-guide-twig?view=input" rel="nofollow noreferrer">StraightUpCraft</a></strong> page.  Scroll to the very bottom for tables.</p>

CC BY-SA 3.0
2017-09-12T22:26:42.517Z
2017-09-12T22:26:42.517Z
Ryan
<p>I'm trying to submit a form containing items from a users' cart, using A&amp;M forms, but cannot seem to populate the table field with the items. I'm using the code below:</p>

<pre><code>{% for item in cart.lineItems %}
    &lt;input type="hidden" name="fields[selections][{{loop.index}}][col1]" value="{{item.qty}} x {{item.description}}"&gt;
{% endfor %}
</code></pre>

<p>For some reason, though, it's creating the rows in the table, but not actually populating it with any content. Any idea what to do to get it to work?</p>

<p>Thanks!</p>

<plugin-amforms>
A&M Form Table Field Submission
# A&M Form Table Field Submission

(Asked by: username_0 on 2016-09-12)

I'm trying to submit a form containing items from a users' cart, using A&M forms, but cannot seem to populate the table field with the items. I'm using the code below:
{% for item in cart.lineItems %}
    
{% endfor %}

For some reason, though, it's creating the rows in the table, but not actually populating it with any content. Any idea what to do to get it to work?
Thanks!

**Tags:** plugin-amforms


---

## 1 answers

### Answer by username_1 on 2017-09-12. Score: 1

I know I'm a bit late to this, but I think it's because your `{{ loop.index }}` is not **[0-indexed](https://twig.symfony.com/doc/2.x/tags/for.html#the-loop-variable)**, which is necessary for the array. It should look like this:

You also need an extra valueless `hidden` field above the loop to collect all the values into one array:

You can see a fuller example on how to format the HTML for all fields of all types on this **[StraightUpCraft](https://straightupcraft.com/articles/craft-cms-field-guide-twig?view=input)** page. Scroll to the very bottom for tables.


---

