ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
with_keys.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
23 function with_keys()
24 {
25  //Step 0: Declare dependencies
26  global $DIC;
27  $ui = $DIC->ui()->factory();
28  $renderer = $DIC->ui()->renderer();
29  $request = $DIC->http()->request();
30 
31  //Step 1: Define the input fields
32  $some_input = $ui->input()->field()
33  ->text("Input", "Any Input");
34 
35  //Step 2: Define the form action to target the input processing
36  $DIC->ctrl()->setParameterByClass(
37  'ilsystemstyledocumentationgui',
38  'example_name',
39  'keys'
40  );
41  $form_action = $DIC->ctrl()->getFormActionByClass('ilsystemstyledocumentationgui');
42 
43  //Step 5: Define the form, plugin the inputs and attach some transformation acting
44  // on the complete input of the form.
45  $form = $ui->input()->container()->form()->standard(
46  $form_action,
47  [ 'input1' => $some_input->withLabel("Input 1")
48  , 'input2' => $some_input->withLabel("Input 2")
49  ]
50  );
51 
52  //Step 6: Define some data processing.
53  if ($request->getMethod() == "POST"
54  && array_key_exists('example_name', $request->getQueryParams())
55  && $request->getQueryParams()['example_name'] == 'keys') {
56  $form = $form->withRequest($request);
57  $result = $form->getData();
58  } else {
59  $result = "No result yet.";
60  }
61 
62  //Step 7: Render the form and the result of the data processing
63  return
64  "<pre>" . print_r($result, true) . "</pre><br/>" .
65  $renderer->render($form);
66 }
$renderer
global $DIC
Definition: shib_login.php:25
with_keys()
description: > Example showing how keys can be used when attaching input fields to a form...
Definition: with_keys.php:23