ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
base_with_data.php
Go to the documentation of this file.
1<?php
6function base_with_data()
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 $multi_select_input = $ui->input()->field()->tag(
16 "Basic TagInput",
17 ['Interesting', 'Boring', 'Animating', 'Repetitious'],
18 "Just some tags"
19 );
20
21 // Step 2, define form and form actions
22 $DIC->ctrl()->setParameterByClass(
23 ilSystemStyleDocumentationGUI::class,
24 'example_name',
25 'tag_inputs'
26 );
27 $DIC->ctrl()->saveParameterByClass(
28 ilSystemStyleDocumentationGUI::class,
29 'node_id'
30 );
31
32 $form_action = $DIC->ctrl()->getFormActionByClass(ilSystemStyleDocumentationGUI::class);
33 $form = $ui->input()->container()->form()->standard($form_action, [$multi_select_input]);
34
35 // Step 4, implement some form data processing.
36 if ($request->getMethod() === "POST" && $request->getQueryParams()['example_name'] === 'tag_inputs') {
37 $form = $form->withRequest($request);
38 $result = $form->getData();
39 } else {
40 $result = "No result yet.";
41 }
42
43 // Return the rendered form
44 return "<pre>" . print_r($result, true) . "</pre><br/>" . $renderer->render($form);
45}
$result
foreach($paths as $path) $request
Definition: asyncclient.php:32
base_with_data()
Example show how to create and render a basic tag input field and attach it to a form.
An exception for terminatinating execution or to throw for unit testing.
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7