You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/php/api/form_builder/form_fields.md
+167Lines changed: 167 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,11 +37,26 @@ Objects of this class require a label.
37
37
The return value of `getSaveValue()` is the integer representation of the boolean value, i.e. `0` or `1`.
38
38
The class implements `IAttributeFormField`, `IAutoFocusFormField`, `ICssClassFormField`, and `IImmutableFormField`.
39
39
40
+
Example:
41
+
42
+
```php
43
+
BooleanFormField::create('example')
44
+
->label('foo.bar.example')
45
+
->value(true)
46
+
```
47
+
40
48
41
49
### `CheckboxFormField`
42
50
43
51
`CheckboxFormField` extends `BooleanFormField` and offers a simple HTML checkbox.
44
52
53
+
Example:
54
+
55
+
```php
56
+
CheckboxFormField::create('example')
57
+
->label('foo.bar.example')
58
+
```
59
+
45
60
46
61
### `ClassNameFormField`
47
62
@@ -58,6 +73,15 @@ The class implements `IAttributeFormField`, `IAutoFocusFormField`, `ICssClassFor
58
73
59
74
Additionally, the default id of a `ClassNameFormField` object is `className`, the default label is `wcf.form.field.className`, and if either an interface or a parent class is required, a default description is set if no description has already been set (`wcf.form.field.className.description.interface` and `wcf.form.field.className.description.parentClass`, respectively).
60
75
76
+
Example:
77
+
78
+
```php
79
+
ClassNameFormField::create('example')
80
+
->label('foo.bar.example')
81
+
->classExists()
82
+
->implementedInterface(ExampleInterface::class)
83
+
```
84
+
61
85
62
86
### `CurrencyFormField`
63
87
@@ -87,44 +111,101 @@ The following methods are specific to this form field class:
87
111
-`supportTime($supportsTime = true)` and `supportsTime()` can be used to toggle whether, in addition to a date, a time can also be specified.
`DescriptionFormField` is a [multi-line text form field](#multilinetextformfield) with `description` as the default id and `wcf.global.description` as the default label.
94
126
127
+
Example:
128
+
129
+
```php
130
+
DescriptionFormField::create('example')
131
+
```
132
+
95
133
96
134
### `EmailFormField`
97
135
98
136
`EmailFormField` is a form field to enter an email address which is internally validated using `UserUtil::isValidEmail()`.
99
137
The class implements `IAttributeFormField`, `IAutoCompleteFormField`, `IAutoFocusFormField`, `ICssClassFormField`, `II18nFormField`, `IImmutableFormField`, `IInputModeFormField`, `IPatternFormField`, and `IPlaceholderFormField`.
100
138
139
+
Example:
140
+
141
+
```php
142
+
EmailFormField::create('example')
143
+
->label('foo.bar.example')
144
+
```
145
+
101
146
102
147
### `FloatFormField`
103
148
104
149
`FloatFormField` is an implementation of [AbstractNumericFormField](#abstractnumericformfield) for floating point numbers.
105
150
151
+
Example:
152
+
153
+
```php
154
+
FloatFormField::create('example')
155
+
->label('foo.bar.example')
156
+
->value(0.5)
157
+
```
158
+
106
159
107
160
### `HiddenFormField`
108
161
109
162
`HiddenFormField` is a form field without any user-visible UI.
110
163
Even though the form field is invisible to the user, the value can still be modified by the user, e.g. by leveraging the web browsers developer tools.
111
164
The `HiddenFormField`*must not* be used to transfer sensitive information or information that the user should not be able to modify.
112
165
166
+
Example:
167
+
168
+
```php
169
+
HiddenFormField::create('example')
170
+
->value('hidden value')
171
+
```
172
+
113
173
114
174
### `IconFormField`
115
175
116
176
`IconFormField` is a form field to select a FontAwesome icon.
117
177
178
+
Example:
179
+
180
+
```php
181
+
IconFormField::create('example')
182
+
->label('foo.bar.example')
183
+
```
184
+
118
185
119
186
### `IntegerFormField`
120
187
121
188
`IntegerFormField` is an implementation of [AbstractNumericFormField](#abstractnumericformfield) for integers.
122
189
190
+
Example:
191
+
192
+
```php
193
+
IntegerFormField::create('example')
194
+
->label('foo.bar.example')
195
+
->value(10)
196
+
```
123
197
124
198
### `IsDisabledFormField`
125
199
126
200
`IsDisabledFormField` is a [boolean form field](#booleanformfield) with `isDisabled` as the default id.
127
201
202
+
Example:
203
+
204
+
```php
205
+
IsDisabledFormField::create()
206
+
->label('foo.bar.example')
207
+
```
208
+
128
209
129
210
### `ItemListFormField`
130
211
@@ -142,6 +223,14 @@ By default, `ItemListFormField::SAVE_VALUE_TYPE_CSV` is used.
142
223
143
224
If `ItemListFormField::SAVE_VALUE_TYPE_ARRAY` is used as save value type, `ItemListFormField` objects register a [custom form field data processor](validation_data.md#customformfielddataprocessor) to add the relevant array into the `$parameters` array directly using the object property as the array key.
`RadioButtonFormField` is a form fields that allows the selection of a single option out of a predefined list of available options using radiobuttons.
188
297
The class implements `IAttributeFormField`, `ICssClassFormField`, `IImmutableFormField`, and `ISelectionFormField`.
189
298
299
+
Example:
300
+
301
+
```php
302
+
RadioButtonFormField::create('example')
303
+
->label('foo.bar.example')
304
+
->options([
305
+
1 => 'one',
306
+
2 => 'two',
307
+
])
308
+
```
190
309
191
310
### `RatingFormField`
192
311
@@ -198,6 +317,15 @@ When the field is shown, there will be `maximum() - minimum() + 1` icons be show
198
317
If a rating values is set, the first `getValue()` icons will instead use the classes that can be set and gotten via `activeCssClasses(array $cssClasses)` and `getActiveCssClasses()`.
199
318
By default, the only default class is `star-o` and the active classes are `star` and `orange`.
200
319
320
+
Example:
321
+
322
+
```php
323
+
RatingFormField::create('example')
324
+
->label('foo.bar.example')
325
+
->minimum(1)
326
+
->maximum(5)
327
+
```
328
+
201
329
202
330
### `SelectFormField`
203
331
@@ -220,34 +348,73 @@ The default id of instances of this class is `showOrder` and their default label
220
348
221
349
!!! info "It is important that the relevant object property is always kept updated. Whenever a new object is added or an existing object is edited or delete, the values of the other objects have to be adjusted to ensure consecutive numbering."
222
350
351
+
Example:
352
+
353
+
```php
354
+
ShowOrderFormField::create('example')
355
+
->options(new FooList())
356
+
```
357
+
223
358
224
359
### `SingleSelectionFormField`
225
360
226
361
`SingleSelectionFormField` is a form fields that allows the selection of a single option out of a predefined list of available options.
227
362
The class implements `ICssClassFormField`, `IFilterableSelectionFormField`, `IImmutableFormField`, and `INullableFormField`.
228
363
If the field is nullable and the current form field value is considered `empty` by PHP, `null` is returned as the save value.
229
364
365
+
Example:
366
+
367
+
```php
368
+
SingleSelectionFormField::create('example')
369
+
->options(['option1', 'option2', 'option3'])
370
+
```
371
+
230
372
231
373
### `SortOrderFormField`
232
374
233
375
`SingleSelectionFormField` is a [single selection form field](#singleselectionformfield) with default id `sortOrder`, default label `wcf.global.showOrder` and default options `ASC: wcf.global.sortOrder.ascending` and `DESC: wcf.global.sortOrder.descending`.
234
376
377
+
Example:
378
+
379
+
```php
380
+
SingleSelectionFormField::create('example')
381
+
```
382
+
235
383
236
384
### `TextFormField`
237
385
238
386
`TextFormField` is a form field that allows entering a single line of text.
239
387
The class implements `IAttributeFormField`, `IAutoCompleteFormField`, `ICssClassFormField`, `IImmutableFormField`, `II18nFormField`, `IInputModeFormField`, `IMaximumLengthFormField`, `IMinimumLengthFormField`, `IPatternFormField`, and `IPlaceholderFormField`.
240
388
389
+
Example:
390
+
391
+
```php
392
+
TextFormField::create('example')
393
+
->label('foo.bar.example')
394
+
```
395
+
241
396
242
397
### `TitleFormField`
243
398
244
399
`TitleFormField` is a [text form field](#textformfield) with `title` as the default id and `wcf.global.title` as the default label.
245
400
401
+
Example:
402
+
403
+
```php
404
+
TitleFormField::create()
405
+
```
406
+
246
407
247
408
### `UrlFormField`
248
409
249
410
`UrlFormField` is a [text form field](#textformfield) whose values are checked via `Url::is()`.
0 commit comments