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
18 //Step 1: Define the fields in the group
19 $dependant_field = $ui->input()->field()->text("Item 1", "Just some dependent group field");
20 $dependant_field2 = $ui->input()->field()->datetime("Item 2", "a dependent date");
21
22 //Step 2: define the checkbox and attach the dependant group
23 $checkbox_input = $ui->input()->field()->optionalGroup(
24 [
25 "dependant_text" => $dependant_field,
26 "dependant_date" => $dependant_field2
27 ],
28 "Optional Group",
29 "Check to display group field."
30 );
31
32 //Step 3: define form and form actions
33 $form = $ui->input()->container()->form()->standard('#', [ $checkbox_input]);
34
35 //Step 4: implement some form data processing. Note, the value of the checkbox will
36 // be 'checked' if checked an null if unchecked.
37 if ($request->getMethod() == "POST") {
38 $form = $form->withRequest($request);
39 $result = $form->getData();
40 } else {
41 $result = "No result yet.";
42 }
43
44 //Step 5: Render the checkbox with the enclosing form.
45 return
46 "<pre>" . print_r($result, true) . "</pre><br/>" .
47 $renderer->render($form);
48}
global $DIC
Definition: feed.php:28
base()
Example showing how a dependant group (aka sub form) might be attached to a checkbox.
Definition: base.php:10