ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
numeric_inputs.php
Go to the documentation of this file.
1 <?php
5 function numeric_inputs()
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: Declare the numeric input
14  $number_input = $ui->input()->field()
15  ->numeric("Some Number", "Put in a number.")
16  ->withValue(133);
17 
18  $number_input2 = $number_input->withRequired(true)->withValue('');
19 
20  //Step 2, define form
21  $form = $ui->input()->container()->form()->standard('#', [
22  'n1' => $number_input,
23  'n2' => $number_input2
24  ]);
25 
26  //Step 3, implement some form data processing.
27  if ($request->getMethod() == "POST") {
28  $form = $form->withRequest($request);
29  $result = $form->getData();
30  } else {
31  $result = "No result yet.";
32  }
33 
34  //Return the rendered form
35  return
36  "<pre>" . print_r($result, true) . "</pre><br/>" .
37  $renderer->render($form);
38 }
$result
foreach($paths as $path) $request
Definition: asyncclient.php:32
global $DIC
Definition: saml.php:7
if(isset($_POST['submit'])) $form
numeric_inputs()
Base example showing how to plug a numeric input into a form.