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
+65-12Lines changed: 65 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,12 +2,14 @@
2
2
3
3
## Abstract Form Fields
4
4
5
-
The following form field classes cannot be instantiated directly because they are abstract, but they can/must be used when creating own form field classes.
5
+
The following form field classes cannot be instantiated directly because they are abstract, but they can/must be used when creating own form field classes.
6
+
6
7
7
8
### `AbstractFormField`
8
9
9
10
`AbstractFormField` is the abstract default implementation of the `IFormField` interface and it is expected that every implementation of `IFormField` implements the interface by extending this class.
10
11
12
+
11
13
### `AbstractNumericFormField`
12
14
13
15
`AbstractNumericFormField` is the abstract implementation of a form field handling a single numeric value.
@@ -29,19 +31,22 @@ If the implementation of a more specific interface is required then the remainin
29
31
30
32
The following form fields are general reusable fields without any underlying context.
31
33
34
+
32
35
### `BooleanFormField`
33
36
34
37
`BooleanFormField` is used for boolean (`0` or `1`, `yes` or `no`) values.
35
38
Objects of this class require a label.
36
39
The return value of `getSaveValue()` is the integer representation of the boolean value, i.e. `0` or `1`.
37
40
The class implements `IAttributeFormField`, `IAutoFocusFormField`, `ICssClassFormField`, and `IImmutableFormField`.
38
41
42
+
39
43
### `CheckboxFormField`
40
44
41
45
!!! info "Only available since version 5.3.2."
42
46
43
47
`CheckboxFormField` extends `BooleanFormField` and offers a simple HTML checkbox.
44
48
49
+
45
50
### `ClassNameFormField`
46
51
47
52
`ClassNameFormField` is a [text form field](#textformfield) that supports additional settings, specific to entering a PHP class name:
@@ -57,6 +62,7 @@ The class implements `IAttributeFormField`, `IAutoFocusFormField`, `ICssClassFor
57
62
58
63
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).
59
64
65
+
60
66
### `DateFormField`
61
67
62
68
`DateFormField` is a form field to enter a date (and optionally a time).
@@ -72,37 +78,45 @@ The following methods are specific to this form field class:
72
78
-`supportTime($supportsTime = true)` and `supportsTime()` can be used to toggle whether, in addition to a date, a time can also be specified.
73
79
By default, specifying a time is disabled.
74
80
81
+
75
82
### `DescriptionFormField`
76
83
77
84
`DescriptionFormField` is a [multi-line text form field](#multilinetextformfield) with `description` as the default id and `wcf.global.description` as the default label.
78
85
86
+
79
87
### `EmailFormField`
80
88
81
89
`EmailFormField` is a form field to enter an email address which is internally validated using `UserUtil::isValidEmail()`.
82
90
The class implements `IAttributeFormField`, `IAutoCompleteFormField`, `IAutoFocusFormField`, `ICssClassFormField`, `II18nFormField`, `IImmutableFormField`, `IInputModeFormField`, `IPatternFormField`, and `IPlaceholderFormField`.
83
91
92
+
84
93
### `FloatFormField`
85
94
86
95
`FloatFormField` is an implementation of [AbstractNumericFormField](#abstractnumericformfield) for floating point numbers.
87
96
97
+
88
98
### `HiddenFormField`
89
99
90
100
`HiddenFormField` is a form field without any user-visible UI.
91
101
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.
92
-
The `HiddenFormField`_must not_ be used to transfer sensitive information or information that the user should not be able to modify.
102
+
The `HiddenFormField`*must not* be used to transfer sensitive information or information that the user should not be able to modify.
103
+
93
104
94
105
### `IconFormField`
95
106
96
107
`IconFormField` is a form field to select a FontAwesome icon.
97
108
109
+
98
110
### `IntegerFormField`
99
111
100
112
`IntegerFormField` is an implementation of [AbstractNumericFormField](#abstractnumericformfield) for integers.
101
113
114
+
102
115
### `IsDisabledFormField`
103
116
104
117
`IsDisabledFormField` is a [boolean form field](#booleanformfield) with `isDisabled` as the default id.
105
118
119
+
106
120
### `ItemListFormField`
107
121
108
122
`ItemListFormField` is a form field in which multiple values can be entered and returned in different formats as save value.
@@ -119,23 +133,28 @@ By default, `ItemListFormField::SAVE_VALUE_TYPE_CSV` is used.
119
133
120
134
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.
121
135
136
+
122
137
### `MultilineTextFormField`
123
138
124
139
`MultilineTextFormField` is a [text form field](#textformfield) that supports multiple rows of text.
125
140
The methods `rows($rows)` and `getRows()` can be used to set and get the number of rows of the `textarea` elements.
126
141
The default number of rows is `10`.
127
142
These methods do **not**, however, restrict the number of text rows that can be entered.
128
143
144
+
129
145
### `MultipleSelectionFormField`
130
146
131
147
`MultipleSelectionFormField` is a form fields that allows the selection of multiple options out of a predefined list of available options.
132
-
The class implements `IAttributeFormField`, `ICssClassFormField`, `IFilterableSelectionFormField`, `IImmutableFormField`.
148
+
The class implements `IAttributeFormField`, `ICssClassFormField`, `IFilterableSelectionFormField`, `IImmutableFormField`, and `INullableFormField`.
149
+
If the field is nullable and no option is selected, `null` is returned as the save value.
150
+
133
151
134
152
### `RadioButtonFormField`
135
153
136
154
`RadioButtonFormField` is a form fields that allows the selection of a single option out of a predefined list of available options using radiobuttons.
137
155
The class implements `IAttributeFormField`, `ICssClassFormField`, `IImmutableFormField`, and `ISelectionFormField`.
138
156
157
+
139
158
### `RatingFormField`
140
159
141
160
`RatingFormField` is a form field to set a rating for an object.
@@ -144,7 +163,8 @@ Form fields of this class have `rating` as their default id, `wcf.form.field.rat
144
163
For this field, the minimum and maximum refer to the minimum and maximum rating an object can get.
145
164
When the field is shown, there will be `maximum() - minimum() + 1` icons be shown with additional CSS classes that can be set and gotten via `defaultCssClasses(array $cssClasses)` and `getDefaultCssClasses()`.
146
165
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()`.
147
-
By default, the only default class is `fa-star-o` and the active classes are `fa-star` and `orange`.
166
+
By default, the only default class is `fa-star-o` and the active classes are `fa-star` and `orange`.
167
+
148
168
149
169
### `ShowOrderFormField`
150
170
@@ -155,33 +175,41 @@ The default id of instances of this class is `showOrder` and their default label
155
175
156
176
!!! 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."
157
177
178
+
158
179
### `SingleSelectionFormField`
159
180
160
181
`SingleSelectionFormField` is a form fields that allows the selection of a single option out of a predefined list of available options.
161
182
The class implements `ICssClassFormField`, `IFilterableSelectionFormField`, `IImmutableFormField`, and `INullableFormField`.
162
183
If the field is nullable and the current form field value is considered `empty` by PHP, `null` is returned as the save value.
163
184
185
+
164
186
### `SortOrderFormField`
165
187
166
188
`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`.
167
189
190
+
168
191
### `TextFormField`
169
192
170
193
`TextFormField` is a form field that allows entering a single line of text.
171
194
The class implements `IAttributeFormField`, `IAutoCompleteFormField`, `ICssClassFormField`, `IImmutableFormField`, `II18nFormField`, `IInputModeFormField`, `IMaximumLengthFormField`, `IMinimumLengthFormField`, `IPatternFormField`, and `IPlaceholderFormField`.
172
195
196
+
173
197
### `TitleFormField`
174
198
175
199
`TitleFormField` is a [text form field](#textformfield) with `title` as the default id and `wcf.global.title` as the default label.
176
200
201
+
177
202
### `UrlFormField`
178
203
179
204
`UrlFormField` is a [text form field](#textformfield) whose values are checked via `Url::is()`.
180
205
206
+
207
+
181
208
## Specific Fields
182
209
183
210
The following form fields are reusable fields that generally are bound to a certain API or `DatabaseObject` implementation.
184
211
212
+
185
213
### `AclFormField`
186
214
187
215
`AclFormField` is used for setting up acl values for specific objects.
@@ -194,34 +222,39 @@ A category name of `null` signals that no category filter is used.
194
222
`AclFormField` objects register a [custom form field data processor](validation_data.md#customformfielddataprocessor) to add the relevant ACL object type id into the `$parameters` array directly using `{$objectProperty}_aclObjectTypeID` as the array key.
195
223
The relevant database object action method is expected, based on the given ACL object type id, to save the ACL option values appropriately.
196
224
225
+
197
226
### `ButtonFormField`
198
227
199
228
!!! info "Only available since version 5.4."
200
229
201
230
`ButtonFormField` shows a submit button as part of the form.
202
231
The class implements `IAttributeFormField` and `ICssClassFormField`.
203
232
204
-
Specifically for this form field, there is the `IsNotClickedFormFieldDependency` dependency with which certain parts of the form will only be processed if the relevent button has not clicked.
233
+
Specifically for this form field, there is the `IsNotClickedFormFieldDependency` dependency with which certain parts of the form will only be processed if the relevent button has not clicked.
234
+
205
235
206
236
### `CaptchaFormField`
207
237
208
238
`CaptchaFormField` is used to add captcha protection to the form.
209
239
210
240
You must specify a captcha object type (`com.woltlab.wcf.captcha`) using the `objectType()` method.
211
241
242
+
212
243
### `ColorFormField`
213
244
214
245
!!! info "Only available since version 5.5."
215
246
216
247
`ColorFormField` is used to specify RGBA colors using the `rgba(r, g, b, a)` format.
217
248
The class implements `IImmutableFormField`.
218
249
250
+
219
251
### `ContentLanguageFormField`
220
252
221
253
`ContentLanguageFormField` is used to select the content language of an object.
222
-
Fields of this class are only available if multilingualism is enabled and if there are content languages.
254
+
Fields of this class are only available if multilingualism is enabled and if there are content languages.
223
255
The class implements `IImmutableFormField`.
224
256
257
+
225
258
### `LabelFormField`
226
259
227
260
`LabelFormField` is used to select a label from a specific label group.
@@ -231,12 +264,14 @@ The `labelGroup(ViewableLabelGroup $labelGroup)` and `getLabelGroup()` methods a
231
264
Additionally, there is the static method `createFields($objectType, array $labelGroups, $objectProperty = 'labelIDs)` that can be used to create all relevant label form fields for a given list of label groups.
232
265
In most cases, `LabelFormField::createFields()` should be used.
233
266
267
+
234
268
### `OptionFormField`
235
269
236
270
`OptionFormField` is an [item list form field](#itemlistformfield) to set a list of options.
237
271
The class implements `IPackagesFormField` and only options of the set packages are considered available.
238
272
The default label of instances of this class is `wcf.form.field.option` and their default id is `options`.
239
273
274
+
240
275
### `SimpleAclFormField`
241
276
242
277
`SimpleAclFormField` is used for setting up simple acl values (one `yes`/`no` option per user and user group) for specific objects.
@@ -257,6 +292,7 @@ The following methods are specific to this form field class:
257
292
-`imageOnly($imageOnly = true)` and `isImageOnly()` can be used to set and check if only images may be selected.
258
293
-`getMedia()` returns the media file based on the current field value if a field is set.
259
294
295
+
260
296
### `TagFormField`
261
297
262
298
`TagFormField` is a form field to enter tags.
@@ -266,51 +302,57 @@ The default label of instances of this class is `wcf.tagging.tags` and their def
266
302
267
303
`TagFormField` objects register a [custom form field data processor](validation_data.md#customformfielddataprocessor) to add the array with entered tag names into the `$parameters` array directly using the object property as the array key.
268
304
305
+
269
306
### `UploadFormField`
270
307
271
308
`UploadFormField` is a form field that allows uploading files by the user.
272
309
273
-
`UploadFormField` objects register a [custom form field data processor](validation_data.md#customformfielddataprocessor) to add the array of `wcf\system\file\upload\UploadFile\UploadFile` into the `$parameters` array directly using the object property as the array key. Also it registers the removed files as an array of `wcf\system\file\upload\UploadFile\UploadFile` into the `$parameters` array directly using the object property with the suffix `_removedFiles` as the array key.
274
-
275
-
The field supports additional settings:
310
+
`UploadFormField` objects register a [custom form field data processor](validation_data.md#customformfielddataprocessor) to add the array of `wcf\system\file\upload\UploadFile\UploadFile` into the `$parameters` array directly using the object property as the array key. Also it registers the removed files as an array of `wcf\system\file\upload\UploadFile\UploadFile` into the `$parameters` array directly using the object property with the suffix `_removedFiles` as the array key.
276
311
312
+
The field supports additional settings:
277
313
-`imageOnly($imageOnly = true)` and `isImageOnly()` can be used to ensure that the uploaded files are only images.
278
314
-`allowSvgImage($allowSvgImages = true)` and `svgImageAllowed()` can be used to allow SVG images, if the image only mode is enabled (otherwise, the method will throw an exception). By default, SVG images are not allowed.
279
315
280
-
#### Provide value from database object
316
+
#### Provide value from database object
281
317
282
318
To provide values from a database object, you should implement the method `get{$objectProperty}UploadFileLocations()` to your database object class. This method must return an array of strings with the locations of the files.
283
319
284
-
#### Process files
320
+
#### Process files
285
321
286
322
To process files in the database object action class, you must [`rename`](https://secure.php.net/manual/en/function.rename.php) the file to the final destination. You get the temporary location, by calling the method `getLocation()` on the given `UploadFile` objects. After that, you call `setProcessed($location)` with `$location` contains the new file location. This method sets the `isProcessed` flag to true and saves the new location. For updating files, it is relevant, whether a given file is already processed or not. For this case, the `UploadFile` object has an method `isProcessed()` which indicates, whether a file is already processed or new uploaded.
287
323
324
+
288
325
### `UserFormField`
289
326
290
327
`UserFormField` is a form field to enter existing users.
291
328
The class implements `IAutoCompleteFormField`, `IAutoFocusFormField`, `IImmutableFormField`, `IMultipleFormField`, and `INullableFormField`.
292
329
While the user is presented the names of the specified users in the user interface, the field returns the ids of the users as data.
293
330
The relevant `UserProfile` objects can be accessed via the `getUsers()` method.
294
331
332
+
295
333
### `UserPasswordField`
296
334
297
335
!!! info "Only available since version 5.4."
298
336
299
337
`UserPasswordField` is a form field for users' to enter their current password.
300
338
The class implements `IAttributeFormField`, `IAttributeFormField`, `IAutoCompleteFormField`, `IAutoFocusFormField`, and `IPlaceholderFormField`
301
339
340
+
302
341
### `UserGroupOptionFormField`
303
342
304
343
`UserGroupOptionFormField` is an [item list form field](#itemlistformfield) to set a list of user group options/permissions.
305
344
The class implements `IPackagesFormField` and only user group options of the set packages are considered available.
306
345
The default label of instances of this class is `wcf.form.field.userGroupOption` and their default id is `permissions`.
307
346
347
+
308
348
### `UsernameFormField`
309
349
310
350
`UsernameFormField` is used for entering one non-existing username.
311
351
The class implements `IAttributeFormField`, `IImmutableFormField`, `IMaximumLengthFormField`, `IMinimumLengthFormField`, `INullableFormField`, and `IPlaceholderFormField`.
312
352
As usernames have a system-wide restriction of a minimum length of 3 and a maximum length of 100 characters, these values are also used as the default value for the field’s minimum and maximum length.
313
353
354
+
355
+
314
356
## Wysiwyg form container
315
357
316
358
To integrate a wysiwyg editor into a form, you have to create a `WysiwygFormContainer` object.
`WysiwygFormField` is used for wysiwyg editor form fields.
@@ -406,17 +449,20 @@ The following methods are specific to this form field class:
406
449
`0` signals that no last edit time has been set.
407
450
-`supportAttachments($supportAttachments)` and `supportsAttachments()` can be used to set and check if the form field supports attachments.
408
451
409
-
!!! warning "It is not sufficient to simply signal attachment support via these methods for attachments to work. These methods are relevant internally to signal the Javascript code that the editor supports attachments. Actual attachment support is provided by `WysiwygAttachmentFormField`."
452
+
!!! warning "It is not sufficient to simply signal attachment support via these methods for attachments to work. These methods are relevant internally to signal the Javascript code that the editor supports attachments. Actual attachment support is provided by `WysiwygAttachmentFormField`."
410
453
411
454
-`supportMentions($supportMentions)` and `supportsMentions()` can be used to set and check if the form field supports mentions of other users.
412
455
413
456
`WysiwygFormField` objects register a [custom form field data processor](validation_data.md#customformfielddataprocessor) to add the relevant simple ACL data array into the `$parameters` array directly using the object property as the array key.
414
457
458
+
415
459
### `TWysiwygFormNode`
416
460
417
461
All form nodes that need to know the id of the `WysiwygFormField` field should use `TWysiwygFormNode`.
418
462
This trait provides `getWysiwygId()` and `wysiwygId($wysiwygId)` to get and set the relevant wysiwyg editor id.
419
463
464
+
465
+
420
466
## Application-Specific Form Fields
421
467
422
468
### WoltLab Suite Forum
@@ -439,26 +485,33 @@ The field supports additional settings:
439
485
By default, external links are shown.
440
486
Like in the example given before, in cases where only actual boards, in which threads can be posted, are relevant, this option allows to exclude external links.
441
487
488
+
489
+
442
490
## Single-Use Form Fields
443
491
444
492
The following form fields are specific for certain forms and hardly reusable in other contexts.
445
493
494
+
446
495
### `BBCodeAttributesFormField`
447
496
448
497
`DevtoolsProjectExcludedPackagesFormField` is a form field for setting the attributes of a BBCode.
449
498
499
+
450
500
### `DevtoolsProjectExcludedPackagesFormField`
451
501
452
502
`DevtoolsProjectExcludedPackagesFormField` is a form field for setting the excluded packages of a devtools project.
453
503
504
+
454
505
### `DevtoolsProjectInstructionsFormField`
455
506
456
507
`DevtoolsProjectExcludedPackagesFormField` is a form field for setting the installation and update instructions of a devtools project.
457
508
509
+
458
510
### `DevtoolsProjectOptionalPackagesFormField`
459
511
460
512
`DevtoolsProjectExcludedPackagesFormField` is a form field for setting the optional packages of a devtools project.
461
513
514
+
462
515
### `DevtoolsProjectRequiredPackagesFormField`
463
516
464
517
`DevtoolsProjectExcludedPackagesFormField` is a form field for setting the required packages of a devtools project.
0 commit comments