Go to the source code of this file.
◆ data_processing()
Example showing how constraints and transformation can be attached to a form.
Definition at line 5 of file data_processing.php.
References $data, $DIC, $form, $l, $lng, $r, $request, $result, and $s.
9 $ui = $DIC->ui()->factory();
10 $lng = $DIC->language();
11 $trafo = new \ILIAS\Transformation\Factory();
12 $data = new \ILIAS\Data\Factory();
13 $validation = new \ILIAS\Validation\Factory(
$data,
$lng);
14 $renderer = $DIC->ui()->renderer();
18 $sum = $trafo->custom(
function ($vs) {
21 return "$l + $r = $s";
24 $from_name = $trafo->custom(
function ($v) {
28 case "three":
return 3;
29 case "four":
return 4;
30 case "five":
return 5;
32 case "seven":
return 7;
33 case "eight":
return 8;
34 case "nine":
return 9;
35 case "ten":
return 10;
37 throw new \LogicException(
"PANIC!");
41 $valid_number = $validation->custom(
function ($v) {
42 return in_array($v, [
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten"]);
43 },
"This is not a number I know...");
47 $number_input = $ui->input()->field()
48 ->text(
"number",
"Put in the name of a number from one to ten.")
49 ->withAdditionalConstraint($valid_number)
50 ->withAdditionalTransformation($from_name);
53 $DIC->ctrl()->setParameterByClass(
54 'ilsystemstyledocumentationgui',
58 $form_action = $DIC->ctrl()->getFormActionByClass(
'ilsystemstyledocumentationgui');
62 $form = $ui->input()->container()->form()->standard(
64 [ $number_input->withLabel(
"Left")
65 , $number_input->withLabel(
"Right")
68 ->withAdditionalTransformation($sum);
72 &&
$request->getQueryParams()[
'example_name'] ==
'data_processing') {
81 "<pre>" . print_r(
$result,
true) .
"</pre><br/>" .
82 $renderer->render(
$form);
foreach($paths as $path) $request
if(isset($_POST['submit'])) $form