ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
with_limits.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
40 function with_limits()
41 {
42  //Step 0: Declare dependencies
43  global $DIC;
44  $ui = $DIC->ui()->factory();
45  $renderer = $DIC->ui()->renderer();
46  $ctrl = $DIC->ctrl();
47  $request = $DIC->http()->request();
48 
49  $min_limit = 3;
50  $max_limit = 20;
51 
52  //Step 1: Define the textarea input field
53  $textarea_input = $ui->input()->field()->textarea("Textarea Input", "Just a textarea input.")->withMinLimit($min_limit)->withMaxLimit($max_limit);
54 
55  //Step 2: Define the form action to target the input processing
56  $DIC->ctrl()->setParameterByClass(
57  'ilsystemstyledocumentationgui',
58  'example_name',
59  'with_limits'
60  );
61  $form_action = $DIC->ctrl()->getFormActionByClass('ilsystemstyledocumentationgui');
62 
63  //Step 3: Define the form and form actions.
64  $form = $ui->input()->container()->form()->standard($form_action, [$textarea_input]);
65 
66  //Step 4: implement some form data processing.
67  if ($request->getMethod() == "POST" && $request->getQueryParams()['example_name'] == 'with_limits') {
68  $form = $form->withRequest($request);
69  $result = $form->getData();
70  } else {
71  $result = "No result yet.";
72  }
73 
74  //Step 5: Render the form with the text input field
75  return
76  "<pre>" . print_r($result, true) . "</pre><br/>" .
77  $renderer->render($form);
78 }
$renderer
global $DIC
Definition: shib_login.php:22
with_limits()
description: > This example shows how to create and render a basic textarea field with minimum and m...
Definition: with_limits.php:40