1

I have an entry form with both table fields and matrix fields containing table fields. I can save data into the table fields OK with fields[fieldHandle][X][colX] but with the below, I get a matrix block with the first row in the table field created, but no data in the table field's columns:

<input
    type="hidden"
    value="new:1"
    name="fields[fieldHandle][sortOrder][]"
>
<input
    type="hidden"
    value="blockHandle"
    name="fields[fieldHandle][blocks][new:1][type]"
>
<input
    type="text"
    name="'fields[fieldHandle][tableFieldHandle][X][colX]'"
>

What should it be?

1 Answer 1

2

The easiest way to figure this out is to edit an entry with these fields in the CP and monitor the network request that is made on save (or when saving a draft). Here's what I see in my browser dev tools, for example.

Screenshot

Where:

  • Matrix field handle = contentBuilder
  • Table field handle = tableField

So your fields should be set up as follows (in Craft 4).

fields[matrixFieldHandle][blocks][new1][type] = tableFieldHandle
fields[matrixFieldHandle][blocks][new1][enabled] = 1
fields[matrixFieldHandle][blocks][new1][tableFieldHandle][0][col1] = value1
fields[matrixFieldHandle][blocks][new1][tableFieldHandle][0][col2] = value2
fields[matrixFieldHandle][blocks][new1][tableFieldHandle][0][col3] = value3
2
  • Thanks Ben, I did eventually get there on my own, but that's a useful tip. FWIW, what I eventually needed was fields[fieldHandle][new1][fields][blockFieldHandle][X][colX] as well as <input type="hidden" value="1" name="fields[fieldHandle][new1][enabled]"> <input type="hidden" value="blockHandle" name="fields[fieldHandle][new1][type]">.
    – Tyssen
    Oct 30, 2022 at 23:10
  • Updated my answer accordingly.
    – Ben Croker
    Oct 31, 2022 at 23:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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