ILIAS  release_7 Revision v7.30-3-g800a261c036
disabled.php
Go to the documentation of this file.
1<?php
6function disabled()
7{
8 //Step 0: Declare dependencies
9 global $DIC;
10 $ui = $DIC->ui()->factory();
11 $lng = $DIC->language();
12 $renderer = $DIC->ui()->renderer();
13 $request = $DIC->http()->request();
14 $data = new \ILIAS\Data\Factory();
15 $refinery = new \ILIAS\Refinery\Factory($data, $lng);
16
17 //Step 1: Implement transformation and constraints
18 $sum = $refinery->custom()->transformation(function ($vs) {
19 list($l, $r) = $vs;
20 $s = $l + $r;
21 return $s;
22 });
23 $equal_ten = $refinery->custom()->constraint(function ($v) {
24 return $v == 10;
25 }, "The sum must equal ten");
26
27 //Step 2: Define inputs
28 $number_input = $ui->input()->field()->numeric("number", "Put in a number.")->withValue(5);
29
30 //Step 3: Define the group, add the inputs to the group and attach the
31 //transformation and constraint
32 $group = $ui->input()->field()->section(
33 [ $number_input->withLabel("Left"), $number_input->withLabel("Right")],
34 "Equals 10",
35 "Left and Right must equal 10"
36 )
37 ->withAdditionalTransformation($sum)
38 ->withAdditionalTransformation($equal_ten)
39 ->withDisabled(true);
40
41 //Step 3, define form and form actions, attach the group to the form
42 $form = $ui->input()->container()->form()->standard('#', [$group]);
43
44 //Step 4, implement some form data processing.
45 if ($request->getMethod() == "POST") {
46 $form = $form->withRequest($request);
47 $result = $form->getData()[0];
48 } else {
49 $result = "No result yet.";
50 }
51
52 //Return the rendered form
53 return
54 "<pre>" . print_r($result, true) . "</pre><br/>" .
55 $renderer->render($form);
56}
disabled()
Example showing how to plug a disabled checkbox into a form.
Definition: disabled.php:5
$result
An exception for terminatinating execution or to throw for unit testing.
global $DIC
Definition: goto.php:24
$lng
$data
Definition: storeScorm.php:23