ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
with_keys.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
39function with_keys()
40{
41 //Step 0: Declare dependencies
42 global $DIC;
43 $ui = $DIC->ui()->factory();
44 $renderer = $DIC->ui()->renderer();
45 $request = $DIC->http()->request();
46
47 //Step 1: Define the input fields
48 $some_input = $ui->input()->field()
49 ->text("Input", "Any Input");
50
51 //Step 2: Define the form action to target the input processing
52 $DIC->ctrl()->setParameterByClass(
53 'ilsystemstyledocumentationgui',
54 'example_name',
55 'keys'
56 );
57 $form_action = $DIC->ctrl()->getFormActionByClass('ilsystemstyledocumentationgui');
58
59 //Step 5: Define the form, plugin the inputs and attach some transformation acting
60 // on the complete input of the form.
61 $form = $ui->input()->container()->form()->standard(
62 $form_action,
63 [ 'input1' => $some_input->withLabel("Input 1")
64 , 'input2' => $some_input->withLabel("Input 2")
65 ]
66 );
67
68 //Step 6: Define some data processing.
69 if ($request->getMethod() == "POST"
70 && array_key_exists('example_name', $request->getQueryParams())
71 && $request->getQueryParams()['example_name'] == 'keys') {
72 $form = $form->withRequest($request);
73 $result = $form->getData();
74 } else {
75 $result = "No result yet.";
76 }
77
78 //Step 7: Render the form and the result of the data processing
79 return
80 "<pre>" . print_r($result, true) . "</pre><br/>" .
81 $renderer->render($form);
82}
$renderer
global $DIC
Definition: shib_login.php:26