fullscreeninteractive / silverstripe-keyvaluefield
A Silverstripe FormField for extending TextField with several parts (keys)
Package info
github.com/fullscreeninteractive/silverstripe-keyvaluefield
Type:silverstripe-vendormodule
pkg:composer/fullscreeninteractive/silverstripe-keyvaluefield
3.0.0
2026-04-14 00:23 UTC
Requires
- php: ^8.3
- silverstripe/framework: ^6
- silverstripe/vendor-plugin: ^3
Requires (Dev)
- cambis/silverstan: ^2.1
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.3
- silverstripe/standards: ^1
- squizlabs/php_codesniffer: ^3
Suggests
- silverstripe/userforms: Adds EditableKeyValueField and submitted value display; use silverstripe/userforms ^7 with Silverstripe 6.
README
A reusable approach to a form field which extends a simple Text field to have several named parts (keys). This module also supports User Defined Forms.
Installation
composer require fullscreeninteractive/silverstripe-keyvaluefield
Usage
use FullscreenInteractive\KeyValueField\KeyValueField; $fields = new FieldList( KeyValueField::create('Quantity', 'Enter quantity of each size') ->setKeys([ 'Small', 'Medium', 'Large' ]) );
When using ORM managed forms and models (i.e saveInto) data will be saved as
a serialized array of the values to each of the keys. You can change this
behaviour if needed in your Form class.
public function doSave($data, $form) { $quantity = $form->dataFieldByName('Quantity'); // returns an array of key => value $values = json_decode($quantity->dataValue(), true); echo $values['Small'] }
Licence
BSD 3-Clause License
