ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
base.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
50 function base()
51 {
52  //Step 0: Declare dependencies
53  global $DIC;
54  $ui = $DIC->ui()->factory();
55  $renderer = $DIC->ui()->renderer();
56  $request = $DIC->http()->request();
57 
58  //Step 1: Define the fields in the group
59  $dependant_field = $ui->input()->field()->text("Item 1", "Just some dependent group field");
60  $dependant_field2 = $ui->input()->field()->datetime("Item 2", "a dependent date");
61 
62  //Step 2: define the checkbox and attach the dependant group
63  $checkbox_input = $ui->input()->field()->optionalGroup(
64  [
65  "dependant_text" => $dependant_field,
66  "dependant_date" => $dependant_field2
67  ],
68  "Optional Group",
69  "Check to display group field."
70  );
71 
72  //Step 3: define form and form actions
73  $form = $ui->input()->container()->form()->standard('#', [ $checkbox_input]);
74 
75  //Step 4: implement some form data processing. Note, the value of the checkbox will
76  // be 'checked' if checked an null if unchecked.
77  if ($request->getMethod() == "POST") {
78  $form = $form->withRequest($request);
79  $result = $form->getData();
80  } else {
81  $result = "No result yet.";
82  }
83 
84  //Step 5: Render the checkbox with the enclosing form.
85  return
86  "<pre>" . print_r($result, true) . "</pre><br/>" .
87  $renderer->render($form);
88 }
$renderer
base()
description: > Example showing how a dependent group (aka sub form) might be attached to a checkbox...
Definition: base.php:50
global $DIC
Definition: shib_login.php:22