ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
base.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
28 function base()
29 {
30  //declare dependencies
31  global $DIC;
32  $ui = $DIC->ui()->factory();
33  $renderer = $DIC->ui()->renderer();
34  $request = $DIC->http()->request();
35 
36  //define options.
37  $options = array(
38  "1" => "Pick 1",
39  "2" => "Pick 2",
40  "3" => "Pick 3",
41  "4" => "Pick 4",
42  );
43 
44  //define the select
45  $multi = $ui->input()->field()->multiselect("Take your picks", $options, "This is the byline text")
46  ->withRequired(true);
47 
48  //define form and form actions
49  $form = $ui->input()->container()->form()->standard('#', ['multi' => $multi]);
50 
51 
52  //implement some form data processing.
53  if ($request->getMethod() == "POST") {
54  try {
55  $form = $form->withRequest($request);
56  $result = $form->getData();
57  } catch (\InvalidArgumentException $e) {
58  $result = "No result. Probably, the other form was used.";
59  }
60  } else {
61  $result = "No result yet.";
62  }
63 
64  //render the select with the enclosing form.
65  return
66  "<pre>" . print_r($result, true) . "</pre><br/>" .
67  $renderer->render($form);
68 }
$renderer
base()
description: > Base example showing how to plug a Multi-Select into a form.
Definition: base.php:28
global $DIC
Definition: shib_login.php:25