ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
with_limits.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
24 function with_limits()
25 {
26  //Step 0: Declare dependencies
27  global $DIC;
28  $ui = $DIC->ui()->factory();
29  $renderer = $DIC->ui()->renderer();
30  $ctrl = $DIC->ctrl();
31  $request = $DIC->http()->request();
32 
33  $min_limit = 3;
34  $max_limit = 20;
35 
36  //Step 1: Define the textarea input field
37  $textarea_input = $ui->input()->field()->textarea("Textarea Input", "Just a textarea input.")->withMinLimit($min_limit)->withMaxLimit($max_limit);
38 
39  //Step 2: Define the form action to target the input processing
40  $DIC->ctrl()->setParameterByClass(
41  'ilsystemstyledocumentationgui',
42  'example_name',
43  'with_limits'
44  );
45  $form_action = $DIC->ctrl()->getFormActionByClass('ilsystemstyledocumentationgui');
46 
47  //Step 3: Define the form and form actions.
48  $form = $ui->input()->container()->form()->standard($form_action, [$textarea_input]);
49 
50  //Step 4: implement some form data processing.
51  if ($request->getMethod() == "POST" && $request->getQueryParams()['example_name'] == 'with_limits') {
52  $form = $form->withRequest($request);
53  $result = $form->getData();
54  } else {
55  $result = "No result yet.";
56  }
57 
58  //Step 5: Render the form with the text input field
59  return
60  "<pre>" . print_r($result, true) . "</pre><br/>" .
61  $renderer->render($form);
62 }
$renderer
global $DIC
Definition: shib_login.php:25
with_limits()
description: > This example shows how to create and render a basic textarea field with minimum and m...
Definition: with_limits.php:24