ILIAS  release_8 Revision v8.24
base_with_data.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6
12{
13 // Step 0: Declare dependencies
14 global $DIC;
15 $ui = $DIC->ui()->factory();
16 $renderer = $DIC->ui()->renderer();
17 $request = $DIC->http()->request();
18
19 // Step 1: Define the tag input field
20 $tag_input = $ui->input()->field()->tag(
21 "Basic TagInput",
22 ['Interesting & fascinating', 'Boring, dull', 'Animating', 'Repetitious'],
23 "Just some tags"
24 );
25
26 // Step 2, define form and form actions
27 $form = $ui->input()->container()->form()->standard('#', ['f2' => $tag_input]);
28
29 // Step 3, implement some form data processing.
30 if ($request->getMethod() === "POST") {
31 $form = $form->withRequest($request);
32 $result = $form->getData();
33 } else {
34 $result = "No result yet.";
35 }
36
37 // Step 4, return the rendered form with data
38 return "<pre>"
39 . print_r($result, true)
40 . "</pre><br/>"
41 . $renderer->render($form);
42}
global $DIC
Definition: feed.php:28
base_with_data()
Example show how to create and render a basic tag input field and attach it to a form.