ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
with_required.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
39function with_required()
40{
41 //Step 0: Declare dependencies
42 global $DIC;
43
44 $ui = $DIC->ui()->factory();
45 $renderer = $DIC->ui()->renderer();
46 $request = $DIC->http()->request();
47 $ctrl = $DIC->ctrl();
48
49 //Define the options.
50 $options = array(
51 "1" => "Type 1",
52 "2" => "Type 2",
53 "3" => "Type 3",
54 "4" => "Type 4",
55 );
56
57 //Step 1: define the select
58 $select = $ui->input()->field()->select("Choose an Option", $options, "This is the byline text")->withRequired(true);
59
60 //Step 2: define form and form actions
61 $form = $ui->input()->container()->form()->standard('#', [$select]);
62
63 //Step 3: implement some form data processing.
64 if ($request->getMethod() == "POST") {
65 $form = $form->withRequest($request);
66 $result = $form->getData();
67 } else {
68 $result = "No result yet.";
69 }
70
71 //Step 4: Render the select with the enclosing form.
72 return
73 "<pre>" . print_r($result, true) . "</pre><br/>" .
74 $renderer->render($form);
75}
$renderer
global $DIC
Definition: shib_login.php:26