ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
with_required.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
23 function with_required()
24 {
25  //Step 0: Declare dependencies
26  global $DIC;
27 
28  $ui = $DIC->ui()->factory();
29  $renderer = $DIC->ui()->renderer();
30  $request = $DIC->http()->request();
31  $ctrl = $DIC->ctrl();
32 
33  //Define the options.
34  $options = array(
35  "1" => "Type 1",
36  "2" => "Type 2",
37  "3" => "Type 3",
38  "4" => "Type 4",
39  );
40 
41  //Step 1: define the select
42  $select = $ui->input()->field()->select("Choose an Option", $options, "This is the byline text")->withRequired(true);
43 
44  //Step 2: define form and form actions
45  $form = $ui->input()->container()->form()->standard('#', [$select]);
46 
47  //Step 3: implement some form data processing.
48  if ($request->getMethod() == "POST") {
49  $form = $form->withRequest($request);
50  $result = $form->getData();
51  } else {
52  $result = "No result yet.";
53  }
54 
55  //Step 4: Render the select with the enclosing form.
56  return
57  "<pre>" . print_r($result, true) . "</pre><br/>" .
58  $renderer->render($form);
59 }
$renderer
global $DIC
Definition: shib_login.php:25
with_required()
description: > Base example showing how to plug a Select into a form