ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
base.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
70function base()
71{
72 //Step 0: Declare dependencies
73 global $DIC;
74 $ui = $DIC->ui()->factory();
75 $renderer = $DIC->ui()->renderer();
76 $request = $DIC->http()->request();
77 $data = new \ILIAS\Data\Factory();
78
79 //Step 1: Define the groups (with their fields and a label each)
80 $group1 = $ui->input()->field()->group(
81 [
82 "field_1_1" => $ui->input()->field()->text("Item 1.1", "Just some field"),
83 "field_1_2" => $ui->input()->field()->text("Item 1.2", "Just some other field"),
84 "field_1_3" => $ui->input()->field()->datetime("Item 1.3", "a date")->withFormat($data->dateFormat()->germanShort())
85 ],
86 "Switchable Group number one (with numeric key)"
87 );
88 $group2 = $ui->input()->field()->group(
89 [
90 "field_2_1" => $ui->input()->field()->text("Item 2", "Just another field")
91 ->withValue('some val')
92 ],
93 "Switchable Group number two",
94 "with byline"
95 );
96 $group3 = $ui->input()->field()->group([], 'No items in this group', 'but a byline');
97
98 //Step 2: Switchable Group - one or the other:
99 $sg = $ui->input()->field()->switchableGroup(
100 [
101 "1" => $group1,
102 "g2" => $group2,
103 "g3" => $group3
104 ],
105 "Pick One",
106 "...or the other"
107 );
108
109 $form = $ui->input()->container()->form()->standard(
110 '#',
111 [
112 'switchable_group' => $sg,
113 'switchable_group_required' => $sg->withRequired(true),
114 'switchable_group_preset' => $sg->withValue("g2")
115 ->withLabel("Again, Pick One")
116 ->withByline("... or the other.
117 Second option is selected by default here.")
118 ]
119 );
120
121 //Step 3: implement some form data processing.
122 if ($request->getMethod() == "POST") {
123 $form = $form->withRequest($request);
124 $result = $form->getData();
125 } else {
126 $result = "No result yet.";
127 }
128
129 //Step 4: Render.
130 return
131 "<pre>" . htmlspecialchars(print_r($result, true), ENT_QUOTES) . "</pre><br/>" .
132 $renderer->render($form);
133}
$renderer
global $DIC
Definition: shib_login.php:26