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