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 
17 function base()
18 {
19  //Step 0: Declare dependencies
20  global $DIC;
21  $ui = $DIC->ui()->factory();
22  $renderer = $DIC->ui()->renderer();
23  $request = $DIC->http()->request();
24 
25  //Step 1: define the checkbox, and turning it on
26  $checkbox_input = $ui->input()->field()->checkbox("Checkbox", "Check or not.")
27  ->withValue(true);
28 
29  //Step 2: define form and form actions
30  $form = $ui->input()->container()->form()->standard('#', [ $checkbox_input]);
31 
32  //Step 3: implement some form data processing. Note, the value of the checkbox will
33  // be 'checked' if checked an null if unchecked.
34  if ($request->getMethod() == "POST") {
35  $form = $form->withRequest($request);
36  $result = $form->getData();
37  } else {
38  $result = "No result yet.";
39  }
40 
41  //Step 4: Render the checkbox with the enclosing form.
42  return
43  "<pre>" . print_r($result, true) . "</pre><br/>" .
44  $renderer->render($form);
45 }
$renderer
base()
description: > Base example showing how to plug a checkbox into a form.
Definition: base.php:17
global $DIC
Definition: shib_login.php:25