ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
numeric_inputs.php
Go to the documentation of this file.
1<?php
5function 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 and form actions
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
An exception for terminatinating execution or to throw for unit testing.
numeric_inputs()
Base example showing how to plug a numeric input into a form.
$DIC
Definition: xapitoken.php:46