ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
with_keys.php
Go to the documentation of this file.
1 <?php
5 function with_keys()
6 {
7  //Step 0: Declare dependencies
8  global $DIC;
9  $ui = $DIC->ui()->factory();
10  $renderer = $DIC->ui()->renderer();
11  $request = $DIC->http()->request();
12 
13  //Step 1: Define the input fields
14  $number_input = $ui->input()->field()
15  ->text("number", "Some numeric input");
16 
17  //Step 2: Define the form action to target the input processing
18  $DIC->ctrl()->setParameterByClass(
19  'ilsystemstyledocumentationgui',
20  'example_name',
21  'keys'
22  );
23  $form_action = $DIC->ctrl()->getFormActionByClass('ilsystemstyledocumentationgui');
24 
25  //Step 5: Define the form, plugin the inputs and attach some transformation acting
26  // on the complete input of the form.
27  $form = $ui->input()->container()->form()->standard(
28  $form_action,
29  [ 'input1' => $number_input->withLabel("Input 1")
30  , 'input2' => $number_input->withLabel("Input 2")
31  ]
32  );
33 
34  //Step 6: Define some data processing.
35  if ($request->getMethod() == "POST"
36  && $request->getQueryParams()['example_name'] == 'keys') {
37  $form = $form->withRequest($request);
38  $result = $form->getData();
39  } else {
40  $result = "No result yet.";
41  }
42 
43  //Step 7: Render the form and the result of the data processing
44  return
45  "<pre>" . print_r($result, true) . "</pre><br/>" .
46  $renderer->render($form);
47 }
$result
foreach($paths as $path) $request
Definition: asyncclient.php:32
global $DIC
Definition: saml.php:7
with_keys()
Example showing how keys can be used when attaching input fields to a form.
Definition: with_keys.php:5
if(isset($_POST['submit'])) $form