ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
with_required.php
Go to the documentation of this file.
1<?php
5function with_required()
6{
7
8 //Step 0: Declare dependencies
9 global $DIC;
10
11 $ui = $DIC->ui()->factory();
12 $renderer = $DIC->ui()->renderer();
13 $request = $DIC->http()->request();
14 $ctrl = $DIC->ctrl();
15
16 //Define the options.
17 $options = array(
18 "1" => "Type 1",
19 "2" => "Type 2",
20 "3" => "Type 3",
21 "4" => "Type 4",
22 );
23
24 //Step 1: define the select
25 $select = $ui->input()->field()->select("Choose an Option", $options, "This is the byline text")->withRequired(true);
26
27 //Step 2: define form and form actions
28 $ctrl->setParameterByClass(
29 'ilsystemstyledocumentationgui',
30 'example_name_required',
31 'select'
32 );
33 $form_action = $DIC->ctrl()->getFormActionByClass('ilsystemstyledocumentationgui');
34 $form = $ui->input()->container()->form()->standard($form_action, [$select]);
35
36 //Step 3: implement some form data processing.
37 if ($request->getMethod() == "POST"
38 && $request->getQueryParams()['example_name_required'] == "select") {
39 $form = $form->withRequest($request);
40 $result = $form->getData();
41 } else {
42 $result = "No result yet.";
43 }
44
45 //Step 4: Render the select with the enclosing form.
46 return
47 "<pre>" . print_r($result, true) . "</pre><br/>" .
48 $renderer->render($form);
49}
$result
foreach($paths as $path) $request
Definition: asyncclient.php:32
An exception for terminatinating execution or to throw for unit testing.
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
with_required()
Base example showing how to plug a Select into a form.