ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
numeric_inputs.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
10 function numeric_inputs()
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: Declare the numeric input
19  $number_input = $ui->input()->field()
20  ->numeric("Some Number", "Put in a number.")
21  ->withValue(133);
22 
23  $number_input2 = $number_input->withRequired(true)->withValue('');
24 
25  //Step 2, define form and form actions
26  $form = $ui->input()->container()->form()->standard('#', [
27  'n1' => $number_input,
28  'n2' => $number_input2
29  ]);
30 
31  //Step 3, implement some form data processing.
32  if ($request->getMethod() == "POST") {
33  $form = $form->withRequest($request);
34  $result = $form->getData();
35  } else {
36  $result = "No result yet.";
37  }
38 
39  //Return the rendered form
40  return
41  "<pre>" . print_r($result, true) . "</pre><br/>" .
42  $renderer->render($form);
43 }
global $DIC
Definition: feed.php:28
numeric_inputs()
Base example showing how to plug a numeric input into a form.