ILIAS  release_8 Revision v8.24
base.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6
10function base()
11{
12 //Step 0: Declare dependencies
13 global $DIC;
14 $ui = $DIC->ui()->factory();
15 $renderer = $DIC->ui()->renderer();
16 $request = $DIC->http()->request();
17 $data = new \ILIAS\Data\Factory();
18
19 //Step 1: Define the groups (with their fields and a label each)
20 $group1 = $ui->input()->field()->group(
21 [
22 "field_1_1" => $ui->input()->field()->text("Item 1.1", "Just some field"),
23 "field_1_2" => $ui->input()->field()->text("Item 1.2", "Just some other field"),
24 "field_1_3" => $ui->input()->field()->datetime("Item 1.3", "a date")->withFormat($data->dateFormat()->germanShort())
25 ],
26 "Switchable Group number one (with numeric key)"
27 );
28 $group2 = $ui->input()->field()->group(
29 [
30 "field_2_1" => $ui->input()->field()->text("Item 2", "Just another field")
31 ->withValue('some val')
32 ],
33 "Switchable Group number two",
34 "with byline"
35 );
36 $group3 = $ui->input()->field()->group([], 'No items in this group', 'but a byline');
37
38 //Step 2: Switchable Group - one or the other:
39 $sg = $ui->input()->field()->switchableGroup(
40 [
41 "1" => $group1,
42 "g2" => $group2,
43 "g3" => $group3
44 ],
45 "Pick One",
46 "...or the other"
47 );
48
49 $form = $ui->input()->container()->form()->standard(
50 '#',
51 [
52 'switchable_group' => $sg,
53 'switchable_group_required' => $sg->withRequired(true),
54 'switchable_group_preset' => $sg->withValue("g2")
55 ->withLabel("Again, Pick One")
56 ->withByline("... or the other.
57 Second option is selected by default here.")
58 ]
59 );
60
61 //Step 3: implement some form data processing.
62 if ($request->getMethod() == "POST") {
63 $form = $form->withRequest($request);
64 $result = $form->getData();
65 } else {
66 $result = "No result yet.";
67 }
68
69 //Step 4: Render.
70 return
71 "<pre>" . htmlspecialchars(print_r($result, true), ENT_QUOTES) . "</pre><br/>" .
72 $renderer->render($form);
73}
global $DIC
Definition: feed.php:28
base()
Example showing how a dependant group (aka sub form) might be attached to a radio.
Definition: base.php:10