ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
with_dependant_group.php
Go to the documentation of this file.
1 <?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 dependent group (aka sub section)
14  $dependant_field = $ui->input()->field()->text("Item 1", "Just some dependent group field");
15  $dependant_group = $ui->input()->field()->dependantGroup(["dependant_field" => $dependant_field]);
16 
17  //Step 2: define the checkbox and attach the dependant group
18  $checkbox_input = $ui->input()->field()->checkbox("Checkbox", "Check to display dependant field.")
19  ->withDependantGroup($dependant_group);
20 
21  //Step 3: define form and form actions
22  $DIC->ctrl()->setParameterByClass(
23  'ilsystemstyledocumentationgui',
24  'example_name',
25  'dependant_checkbox'
26  );
27  $form_action = $DIC->ctrl()->getFormActionByClass('ilsystemstyledocumentationgui');
28  $form = $ui->input()->container()->form()->standard($form_action, [ $checkbox_input]);
29 
30  //Step 4: implement some form data processing. Note, the value of the checkbox will
31  // be 'checked' if checked an null if unchecked.
32  if ($request->getMethod() == "POST"
33  && $request->getQueryParams()['example_name'] == 'dependant_checkbox') {
34  $form = $form->withRequest($request);
35  $result = $form->getData();
36  } else {
37  $result = "No result yet.";
38  }
39 
40  //Step 5: Render the checkbox with the enclosing form.
41  return
42  "<pre>" . print_r($result, true) . "</pre><br/>" .
43  $renderer->render($form);
44 }
with_dependant_group()
Example showing how a dependant group (aka sub form) might be attached to a checkbox.
$result
foreach($paths as $path) $request
Definition: asyncclient.php:32
global $DIC
Definition: saml.php:7
if(isset($_POST['submit'])) $form