ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
with_required.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
10 function with_required()
11 {
12  //Step 0: Declare dependencies
13  global $DIC;
14 
15  $ui = $DIC->ui()->factory();
16  $renderer = $DIC->ui()->renderer();
17  $request = $DIC->http()->request();
18  $ctrl = $DIC->ctrl();
19 
20  //Define the options.
21  $options = array(
22  "1" => "Type 1",
23  "2" => "Type 2",
24  "3" => "Type 3",
25  "4" => "Type 4",
26  );
27 
28  //Step 1: define the select
29  $select = $ui->input()->field()->select("Choose an Option", $options, "This is the byline text")->withRequired(true);
30 
31  //Step 2: define form and form actions
32  $form = $ui->input()->container()->form()->standard('#', [$select]);
33 
34  //Step 3: implement some form data processing.
35  if ($request->getMethod() == "POST") {
36  $form = $form->withRequest($request);
37  $result = $form->getData();
38  } else {
39  $result = "No result yet.";
40  }
41 
42  //Step 4: Render the select with the enclosing form.
43  return
44  "<pre>" . print_r($result, true) . "</pre><br/>" .
45  $renderer->render($form);
46 }
global $DIC
Definition: feed.php:28
with_required()
Base example showing how to plug a Select into a form.