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 %}
    <input type="hidden" name="fields[selections][{{loop.index}}][col1]" value="{{item.qty}} x {{item.description}}">
{% 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?



I know I'm a bit late to this, but I think it's because your {{ loop.index }} is not 0-indexed, which is necessary for the array. It should look like this:

<input type="hidden" name="fields[selections][{{ loop.index0 }}][col1]" value="{{ item.qty }} x {{ item.description }}">

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

<input type="hidden" name="fields[selections]" value="">

You can see a fuller example on how to format the HTML for all fields of all types on this StraightUpCraft page. Scroll to the very bottom for tables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.