ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
base.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
10 function base()
11 {
12  //declare dependencies
13  global $DIC;
14  $ui = $DIC->ui()->factory();
15  $renderer = $DIC->ui()->renderer();
16  $request = $DIC->http()->request();
17 
18  //define options.
19  $options = array(
20  "1" => "Pick 1",
21  "2" => "Pick 2",
22  "3" => "Pick 3",
23  "4" => "Pick 4",
24  );
25 
26  //define the select
27  $multi = $ui->input()->field()->multiselect("Take your picks", $options, "This is the byline text")
28  ->withRequired(true);
29 
30  //define form and form actions
31  $form = $ui->input()->container()->form()->standard('#', ['multi' => $multi]);
32 
33 
34  //implement some form data processing.
35  if ($request->getMethod() == "POST") {
36  try {
37  $form = $form->withRequest($request);
38  $result = $form->getData();
39  } catch (\InvalidArgumentException $e) {
40  $result = "No result. Probably, the other form was used.";
41  }
42  } else {
43  $result = "No result yet.";
44  }
45 
46  //render the select with the enclosing form.
47  return
48  "<pre>" . print_r($result, true) . "</pre><br/>" .
49  $renderer->render($form);
50 }
base()
Base example showing how to plug a Multi-Select into a form.
Definition: base.php:10
global $DIC
Definition: feed.php:28