ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
13  //Step 0: Declare dependencies
14  global $DIC;
15 
16  $ui = $DIC->ui()->factory();
17  $renderer = $DIC->ui()->renderer();
18  $request = $DIC->http()->request();
19  $ctrl = $DIC->ctrl();
20 
21  //Define the options.
22  $options = array(
23  "1" => "Type 1",
24  "2" => "Type 2",
25  "3" => "Type 3",
26  "4" => "Type 4",
27  );
28 
29  //Step 1: define the select
30  $select = $ui->input()->field()->select("Choose an Option", $options, "This is the byline text")->withRequired(true);
31 
32  //Step 2: define form and form actions
33  $form = $ui->input()->container()->form()->standard('#', [$select]);
34 
35  //Step 3: implement some form data processing.
36  if ($request->getMethod() == "POST") {
37  $form = $form->withRequest($request);
38  $result = $form->getData();
39  } else {
40  $result = "No result yet.";
41  }
42 
43  //Step 4: Render the select with the enclosing form.
44  return
45  "<pre>" . print_r($result, true) . "</pre><br/>" .
46  $renderer->render($form);
47 }
global $DIC
Definition: feed.php:28
with_required()
Base example showing how to plug a Select into a form.