ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
base.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
10 function 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 checkbox, and turning it on
19  $checkbox_input = $ui->input()->field()->checkbox("Checkbox", "Check or not.")
20  ->withValue(true);
21 
22  //Step 2: define form and form actions
23  $form = $ui->input()->container()->form()->standard('#', [ $checkbox_input]);
24 
25  //Step 3: implement some form data processing. Note, the value of the checkbox will
26  // be 'checked' if checked an null if unchecked.
27  if ($request->getMethod() == "POST") {
28  $form = $form->withRequest($request);
29  $result = $form->getData();
30  } else {
31  $result = "No result yet.";
32  }
33 
34  //Step 4: Render the checkbox with the enclosing form.
35  return
36  "<pre>" . print_r($result, true) . "</pre><br/>" .
37  $renderer->render($form);
38 }
base()
Base example showing how to plug a checkbox into a form.
Definition: base.php:10
global $DIC
Definition: feed.php:28