ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
base.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
34 function base()
35 {
36  //Step 0: Declare dependencies
37  global $DIC;
38  $ui = $DIC->ui()->factory();
39  $renderer = $DIC->ui()->renderer();
40  $request = $DIC->http()->request();
41 
42  //Step 1: Define the fields in the group
43  $dependant_field = $ui->input()->field()->text("Item 1", "Just some dependent group field");
44  $dependant_field2 = $ui->input()->field()->datetime("Item 2", "a dependent date");
45 
46  //Step 2: define the checkbox and attach the dependant group
47  $checkbox_input = $ui->input()->field()->optionalGroup(
48  [
49  "dependant_text" => $dependant_field,
50  "dependant_date" => $dependant_field2
51  ],
52  "Optional Group",
53  "Check to display group field."
54  );
55 
56  //Step 3: define form and form actions
57  $form = $ui->input()->container()->form()->standard('#', [ $checkbox_input]);
58 
59  //Step 4: implement some form data processing. Note, the value of the checkbox will
60  // be 'checked' if checked an null if unchecked.
61  if ($request->getMethod() == "POST") {
62  $form = $form->withRequest($request);
63  $result = $form->getData();
64  } else {
65  $result = "No result yet.";
66  }
67 
68  //Step 5: Render the checkbox with the enclosing form.
69  return
70  "<pre>" . print_r($result, true) . "</pre><br/>" .
71  $renderer->render($form);
72 }
$renderer
base()
description: > Example showing how a dependent group (aka sub form) might be attached to a checkbox...
Definition: base.php:34
global $DIC
Definition: shib_login.php:25