ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
disabled.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
16 function disabled()
17 {
18  //Step 0: Declare dependencies
19  global $DIC;
20  $ui = $DIC->ui()->factory();
21  $renderer = $DIC->ui()->renderer();
22  $request = $DIC->http()->request();
23 
24  //Step 1: define the checkbox, and making it disabled
25  $checkbox_input = $ui->input()->field()->checkbox("Checkbox", "Cannot check.")
26  ->withDisabled(true);
27 
28  //Step 2: define form and form actions
29  $form = $ui->input()->container()->form()->standard('#', [ $checkbox_input]);
30 
31  //Step 3: implement some form data processing. Note, the value of the checkbox will
32  // be 'checked' if checked and null if unchecked.
33  if ($request->getMethod() == "POST") {
34  $form = $form->withRequest($request);
35  $result = $form->getData();
36  } else {
37  $result = "No result yet.";
38  }
39 
40  //Step 4: Render the checkbox with the enclosing form.
41  return
42  "<pre>" . print_r($result, true) . "</pre><br/>" .
43  $renderer->render($form);
44 }
$renderer
global $DIC
Definition: shib_login.php:25
disabled()
description: > Example showing how to plug a disabled checkbox into a form
Definition: disabled.php:16