PHP code example of fullscreeninteractive / silverstripe-keyvaluefield

1. Go to this page and download the library: Download fullscreeninteractive/silverstripe-keyvaluefield library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fullscreeninteractive / silverstripe-keyvaluefield example snippets


use FullscreenInteractive\KeyValueField\KeyValueField;

$fields = new FieldList(
    KeyValueField::create('Quantity', 'Enter quantity of each size')
        ->setKeys([
            'Small',
            'Medium',
            'Large'
        ])
);

public function doSave($data, $form)
{
    $quantity = $form->dataFieldByName('Quantity');

    // returns an array of key => value
    $values = json_decode($quantity->dataValue(), true);

    echo $values['Small']
}