ILIAS  trunk Revision v11.0_alpha-1843-g9e1fad99175
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
with_keys.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
39 function 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:22
with_keys()
description: > Example showing how keys can be used when attaching input fields to a form...
Definition: with_keys.php:39