ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
with_keys.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
10 function with_keys()
11 {
12  //Step 0: Declare dependencies
13  global $DIC;
14  $ui = $DIC->ui()->factory();
15  $renderer = $DIC->ui()->renderer();
16  $request = $DIC->http()->request();
17 
18  //Step 1: Define the input fields
19  $some_input = $ui->input()->field()
20  ->text("Input", "Any Input");
21 
22  //Step 2: Define the form action to target the input processing
23  $DIC->ctrl()->setParameterByClass(
24  'ilsystemstyledocumentationgui',
25  'example_name',
26  'keys'
27  );
28  $form_action = $DIC->ctrl()->getFormActionByClass('ilsystemstyledocumentationgui');
29 
30  //Step 5: Define the form, plugin the inputs and attach some transformation acting
31  // on the complete input of the form.
32  $form = $ui->input()->container()->form()->standard(
33  $form_action,
34  [ 'input1' => $some_input->withLabel("Input 1")
35  , 'input2' => $some_input->withLabel("Input 2")
36  ]
37  );
38 
39  //Step 6: Define some data processing.
40  if ($request->getMethod() == "POST"
41  && $request->getQueryParams()['example_name'] == 'keys') {
42  $form = $form->withRequest($request);
43  $result = $form->getData();
44  } else {
45  $result = "No result yet.";
46  }
47 
48  //Step 7: Render the form and the result of the data processing
49  return
50  "<pre>" . print_r($result, true) . "</pre><br/>" .
51  $renderer->render($form);
52 }
global $DIC
Definition: feed.php:28
with_keys()
Example showing how keys can be used when attaching input fields to a form.
Definition: with_keys.php:10