ILIAS  release_7 Revision v7.30-3-g800a261c036
base.php File Reference

Go to the source code of this file.

Functions

 base ()
 Example showing how a dependant group (aka sub form) might be attached to a checkbox. More...
 

Function Documentation

◆ base()

base ( )

Example showing how a dependant group (aka sub form) might be attached to a checkbox.

Definition at line 5 of file base.php.

6{
7 //Step 0: Declare dependencies
8 global $DIC;
9 $ui = $DIC->ui()->factory();
10 $renderer = $DIC->ui()->renderer();
11 $request = $DIC->http()->request();
12
13 //Step 1: Define the field in the group
14 $dependant_field = $ui->input()->field()->text("Item 1", "Just some dependent group field");
15
16 //Step 2: define the checkbox and attach the dependant group
17 $checkbox_input = $ui->input()->field()->optionalGroup(
18 ["dependant_field" => $dependant_field],
19 "Optional Group",
20 "Check to display group field."
21 );
22
23 //Step 3: define form and form actions
24 $form = $ui->input()->container()->form()->standard('#', [ $checkbox_input]);
25
26 //Step 4: implement some form data processing. Note, the value of the checkbox will
27 // be 'checked' if checked an null if unchecked.
28 if ($request->getMethod() == "POST") {
29 $form = $form->withRequest($request);
30 $result = $form->getData();
31 } else {
32 $result = "No result yet.";
33 }
34
35 //Step 5: Render the checkbox with the enclosing form.
36 return
37 "<pre>" . print_r($result, true) . "</pre><br/>" .
38 $renderer->render($form);
39}
$result
global $DIC
Definition: goto.php:24

References $DIC, and $result.