ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
with_limits.php
Go to the documentation of this file.
1<?php
6function with_limits()
7{
8 //Step 0: Declare dependencies
9 global $DIC;
10 $ui = $DIC->ui()->factory();
11 $renderer = $DIC->ui()->renderer();
12 $ctrl = $DIC->ctrl();
13 $request = $DIC->http()->request();
14
15 $min_limit = 3;
16 $max_limit = 20;
17
18 //Step 1: Define the textarea input field
19 $textarea_input = $ui->input()->field()->textarea("Textarea Input", "Just a textarea input.")->withMinLimit($min_limit)->withMaxLimit($max_limit);
20
21 //Step 2: Define the form action to target the input processing
22 $DIC->ctrl()->setParameterByClass(
23 'ilsystemstyledocumentationgui',
24 'example_name',
25 'with_limits'
26 );
27 $form_action = $DIC->ctrl()->getFormActionByClass('ilsystemstyledocumentationgui');
28
29 //Step 3: Define the form and form actions.
30 $form = $ui->input()->container()->form()->standard($form_action, [$textarea_input]);
31
32 //Step 4: implement some form data processing.
33 if ($request->getMethod() == "POST" && $request->getQueryParams()['example_name'] == 'with_limits') {
34 $form = $form->withRequest($request);
35 $result = $form->getData();
36 } else {
37 $result = "No result yet.";
38 }
39
40 //Step 5: Render the form with the text input field
41 return
42 "<pre>" . print_r($result, true) . "</pre><br/>" .
43 $renderer->render($form);
44}
$result
An exception for terminatinating execution or to throw for unit testing.
with_limits()
This example shows how to create and render a basic textarea field with minimum and maximum number of...
Definition: with_limits.php:6
$DIC
Definition: xapitoken.php:46