ILIAS  release_7 Revision v7.30-3-g800a261c036
base_with_data.php File Reference

Go to the source code of this file.

Functions

 base_with_data ()
 Example show how to create and render a basic tag input field and attach it to a form. More...
 

Function Documentation

◆ base_with_data()

base_with_data ( )

Example show how to create and render a basic tag input field and attach it to a form.

This example does not contain any data processing.

Definition at line 6 of file base_with_data.php.

7{
8 // Step 0: Declare dependencies
9 global $DIC;
10 $ui = $DIC->ui()->factory();
11 $renderer = $DIC->ui()->renderer();
12 $request = $DIC->http()->request();
13
14 // Step 1: Define the tag input field
15 $tag_input = $ui->input()->field()->tag(
16 "Basic TagInput",
17 ['Interesting & fascinating', 'Boring, dull', 'Animating', 'Repetitious'],
18 "Just some tags"
19 );
20
21 // Step 2, define form and form actions
22 $form = $ui->input()->container()->form()->standard('#', ['f2' => $tag_input]);
23
24 // Step 3, implement some form data processing.
25 if ($request->getMethod() === "POST") {
26 $form = $form->withRequest($request);
27 $result = $form->getData();
28 } else {
29 $result = "No result yet.";
30 }
31
32 // Step 4, return the rendered form with data
33 return "<pre>"
34 . print_r($result, true)
35 . "</pre><br/>"
36 . $renderer->render($form);
37}
$result
global $DIC
Definition: goto.php:24

References $DIC, and $result.