Skip to main content
added 388 characters in body
Source Link

This isn't documentedI'm trying to insert an entry along with values for a table field. According to the docs, so here'sthe setFieldValues method takes an array of values in the format handle => value, but it doesn't specify how the value should be formatted for each field type.

Here's my best guess at how it might work. This inserts the correct number of rows but for the values are empty, so there's some hidden magic I'm missing...table field:

$product$entry = new Entry();
$product$entry->sectionId = 2;1;
$product$entry->typeId = 2;1;
$product$entry->title = $title;
$product$entry->setFieldValues([
  "fieldHandle""field_handle" => [
    ["column_1_handle" => "hello", "column_2_handle" => "world"], // Row 1
    ["column_1_handle" => "more", "column_2_handle" => "stuff"] // Row 2
  ]
]);

This inserts the correct number of rows into the table field, but the values are empty, so I'm guessing I'm structuring the array incorrectly.

Any ideas?

This isn't documented, so here's my best guess at how it might work. This inserts the correct number of rows but the values are empty, so there's some hidden magic I'm missing...

$product = new Entry();
$product->sectionId = 2;
$product->typeId = 2;
$product->title = $title;
$product->setFieldValues([
  "fieldHandle" => [
    ["column_1_handle" => "hello", "column_2_handle" => "world"], // Row 1
    ["column_1_handle" => "more", "column_2_handle" => "stuff"] // Row 2
  ]
]);

I'm trying to insert an entry along with values for a table field. According to the docs, the setFieldValues method takes an array of values in the format handle => value, but it doesn't specify how the value should be formatted for each field type.

Here's my best guess at how it might work for the table field:

$entry = new Entry();
$entry->sectionId = 1;
$entry->typeId = 1;
$entry->title = $title;
$entry->setFieldValues([
  "field_handle" => [
    ["column_1_handle" => "hello", "column_2_handle" => "world"], // Row 1
    ["column_1_handle" => "more", "column_2_handle" => "stuff"] // Row 2
  ]
]);

This inserts the correct number of rows into the table field, but the values are empty, so I'm guessing I'm structuring the array incorrectly.

Any ideas?

Source Link

How to set field values for the table field type in Craft 3

This isn't documented, so here's my best guess at how it might work. This inserts the correct number of rows but the values are empty, so there's some hidden magic I'm missing...

$product = new Entry();
$product->sectionId = 2;
$product->typeId = 2;
$product->title = $title;
$product->setFieldValues([
  "fieldHandle" => [
    ["column_1_handle" => "hello", "column_2_handle" => "world"], // Row 1
    ["column_1_handle" => "more", "column_2_handle" => "stuff"] // Row 2
  ]
]);