ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
numeric_inputs.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
28 function numeric_inputs()
29 {
30  //Step 0: Declare dependencies
31  global $DIC;
32  $ui = $DIC->ui()->factory();
33  $renderer = $DIC->ui()->renderer();
34  $request = $DIC->http()->request();
35 
36  //Step 1: Declare the numeric input
37  $number_input = $ui->input()->field()
38  ->numeric("Some Number", "Put in a number.")
39  ->withValue(133);
40 
41  $number_input2 = $number_input->withRequired(true)->withValue('');
42 
43  //Step 2, define form and form actions
44  $form = $ui->input()->container()->form()->standard('#', [
45  'n1' => $number_input,
46  'n2' => $number_input2
47  ]);
48 
49  //Step 3, implement some form data processing.
50  if ($request->getMethod() == "POST") {
51  $form = $form->withRequest($request);
52  $result = $form->getData();
53  } else {
54  $result = "No result yet.";
55  }
56 
57  //Return the rendered form
58  return
59  "<pre>" . print_r($result, true) . "</pre><br/>" .
60  $renderer->render($form);
61 }
$renderer
global $DIC
Definition: shib_login.php:25
numeric_inputs()
description: > Base example showing how to plug a numeric input into a form.