Skip to content

Commit a666267

Browse files
committed
usage example for nested form document
1 parent a963771 commit a666267

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,32 @@
11
# de.mysterycode.wcf.formBuilder.extension
22

3+
# Nested form fields
4+
Sometimes you want to store some data serialzed as an array but you want to have a form field for every property.
5+
6+
The form builder introduced in WSC 5.2 is currently not able to handle this case properly, so there is some sort of workaround required.
7+
8+
Usage example:
9+
```PHP
10+
use wcf\system\form\builder\container\DummyFormContainer;
11+
use wcf\system\form\builder\container\FormContainer;
12+
use wcf\system\form\builder\data\processor\PrefixedFormDataProcessor;
13+
use wcf\system\form\builder\NestedFormDocument;
14+
use wcf\system\form\builder\field\TextFormField;
15+
16+
$this->form = NestedFormDocument::create('DummyAdd');
17+
$this->form->appendChildren([
18+
DummyFormContainer::create('additionalData')
19+
->appendChildren([
20+
FormContainer::create('foo')
21+
->label('wcf.dummy.foo')
22+
->appendChildren([
23+
TextFormField::create('additionalData[foo][bar]')
24+
->label('wcf.dummy.foo.bar')
25+
])
26+
])
27+
]);
28+
$this->form->getDataHandler()->addProcessor(new PrefixedFormDataProcessor('additionalData', 'additionalData'));
29+
```
30+
31+
###Attention:
32+
You have to serialize the array manually before writing it to your database!

0 commit comments

Comments
 (0)