1. cliveportman
  2. /code
  3. /saving-craft-cms-supertable-data-from-within-a-plugin-static-supertable-field

Saving Craft CMS supertable data from within a plugin (static supertable field)

If not using a static field, add more rows as appropriate. Static fields require the [0] or they won't save.

$supertableFieldData = array();
$field = craft()->fields->getFieldByHandle('fieldName');
$blockTypes = craft()->superTable->getBlockTypesByFieldId($field->id);
$blockType = $blockTypes[0];
$supertableFieldData[0] = array(
    'type' => $blockType->id,
    'enabled' => true,
    'fields' => array(
         'fieldName' => '7'
    )
); 
$user->setContentFromPost(array('fieldName' => $supertableFieldData));
craft()->users->saveUser($user);