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
+108Lines changed: 108 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -472,26 +472,54 @@ The class implements `IAttributeFormField` and `ICssClassFormField`.
472
472
473
473
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.
474
474
475
+
Example:
476
+
477
+
```php
478
+
ButtonFormField::create('example')
479
+
->buttonLabel('foo.bar.example')
480
+
```
481
+
475
482
476
483
### `CaptchaFormField`
477
484
478
485
`CaptchaFormField` is used to add captcha protection to the form.
479
486
480
487
You must specify a captcha object type (`com.woltlab.wcf.captcha`) using the `objectType()` method.
481
488
489
+
Example:
490
+
491
+
```php
492
+
CaptchaFormField::create('captcha')
493
+
->objectType(CAPTCHA_TYPE)
494
+
```
495
+
482
496
483
497
### `ColorFormField`
484
498
485
499
`ColorFormField` is used to specify RGBA colors using the `rgba(r, g, b, a)` format.
486
500
The class implements `IImmutableFormField`.
487
501
502
+
Example:
503
+
504
+
```php
505
+
ColorFormField::create('example')
506
+
->label('foo.bar.example')
507
+
->value('rgba(1,1,1,1)')
508
+
```
509
+
488
510
489
511
### `ContentLanguageFormField`
490
512
491
513
`ContentLanguageFormField` is used to select the content language of an object.
492
514
Fields of this class are only available if multilingualism is enabled and if there are content languages.
493
515
The class implements `IImmutableFormField`.
494
516
517
+
Example:
518
+
519
+
```php
520
+
ContentLanguageFormField::create()
521
+
```
522
+
495
523
496
524
### `LabelFormField`
497
525
@@ -502,13 +530,29 @@ The `labelGroup(ViewableLabelGroup $labelGroup)` and `getLabelGroup()` methods a
502
530
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.
503
531
In most cases, `LabelFormField::createFields()` should be used.
`OptionFormField` is an [item list form field](#itemlistformfield) to set a list of options.
509
545
The class implements `IPackagesFormField` and only options of the set packages are considered available.
510
546
The default label of instances of this class is `wcf.form.field.option` and their default id is `options`.
511
547
548
+
Example:
549
+
550
+
```php
551
+
OptionFormField::create()
552
+
->description('foo.bar.example')
553
+
->packageIDs([1, 2])
554
+
```
555
+
512
556
513
557
### `SimpleAclFormField`
514
558
@@ -520,6 +564,19 @@ The default label of instances of this class is `wcf.form.field.option` and thei
520
564
521
565
The `SimpleAclFormField` supports inverted permissions, allowing the administrator to grant access to all non-selected users and groups. If this behavior is desired, it needs to be enabled by calling `supportInvertedPermissions`. An `invertPermissions` key containing a boolean value with the users selection will be provided together with the ACL values when saving the field.
522
566
567
+
Example:
568
+
569
+
```php
570
+
SimpleAclFormField::create('example')
571
+
->label('foo.bar.example')
572
+
->supportInvertedPermissions(true)
573
+
->value([
574
+
'allowAll' => false,
575
+
'user' => [1, 2],
576
+
])
577
+
```
578
+
579
+
523
580
### `SingleMediaSelectionFormField`
524
581
525
582
`SingleMediaSelectionFormField` is used to select a specific media file.
@@ -530,6 +587,13 @@ The following methods are specific to this form field class:
530
587
-`imageOnly($imageOnly = true)` and `isImageOnly()` can be used to set and check if only images may be selected.
531
588
-`getMedia()` returns the media file based on the current field value if a field is set.
532
589
590
+
Example:
591
+
592
+
```php
593
+
SingleMediaSelectionFormField::create('example')
594
+
->label('foo.bar.example')
595
+
```
596
+
533
597
534
598
### `TagFormField`
535
599
@@ -540,6 +604,13 @@ The default label of instances of this class is `wcf.tagging.tags` and their def
540
604
541
605
`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.
542
606
607
+
Example:
608
+
609
+
```php
610
+
TagFormField::create()
611
+
->objectType('foo.bar.example.object.type')
612
+
```
613
+
543
614
544
615
### `UploadFormField`
545
616
@@ -552,6 +623,16 @@ The field supports additional settings:
552
623
-`imageOnly($imageOnly = true)` and `isImageOnly()` can be used to ensure that the uploaded files are only images.
553
624
-`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.
554
625
626
+
Example:
627
+
628
+
```php
629
+
UploadFormField::create('example')
630
+
->label('foo.bar.example')
631
+
->maximum(1)
632
+
->imageOnly(true)
633
+
```
634
+
635
+
555
636
#### Provide value from database object
556
637
557
638
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.
@@ -568,26 +649,53 @@ The class implements `IAutoCompleteFormField`, `IAutoFocusFormField`, `IImmutabl
568
649
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.
569
650
The relevant `UserProfile` objects can be accessed via the `getUsers()` method.
570
651
652
+
Example:
653
+
654
+
```php
655
+
UserFormField::create('example')
656
+
->label('foo.bar.example')
657
+
```
658
+
571
659
572
660
### `UserPasswordField`
573
661
574
662
`UserPasswordField` is a form field for users' to enter their current password.
575
663
The class implements `IAttributeFormField`, `IAttributeFormField`, `IAutoCompleteFormField`, `IAutoFocusFormField`, and `IPlaceholderFormField`
576
664
665
+
Example:
666
+
667
+
```php
668
+
UserPasswordField::create()
669
+
->autocomplete('current-password')
670
+
```
671
+
577
672
578
673
### `UserGroupOptionFormField`
579
674
580
675
`UserGroupOptionFormField` is an [item list form field](#itemlistformfield) to set a list of user group options/permissions.
581
676
The class implements `IPackagesFormField` and only user group options of the set packages are considered available.
582
677
The default label of instances of this class is `wcf.form.field.userGroupOption` and their default id is `permissions`.
583
678
679
+
Example:
680
+
681
+
```php
682
+
UserGroupOptionFormField::create()
683
+
->packageIDs([1, 2])
684
+
```
685
+
584
686
585
687
### `UsernameFormField`
586
688
587
689
`UsernameFormField` is used for entering one non-existing username.
588
690
The class implements `IAttributeFormField`, `IImmutableFormField`, `IMaximumLengthFormField`, `IMinimumLengthFormField`, `INullableFormField`, and `IPlaceholderFormField`.
589
691
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.
0 commit comments