ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
base.php
Go to the documentation of this file.
1 <?php
5 function base()
6 {
7  //Step 0: Declare dependencies
8  global $DIC;
9  $ui = $DIC->ui()->factory();
10  $renderer = $DIC->ui()->renderer();
11  $request = $DIC->http()->request();
12 
13  //Step 1: Define the groups (with their fields and a label each)
14  $group1 = $ui->input()->field()->group(
15  [
16  "field_1_1" => $ui->input()->field()->text("Item 1.1", "Just some field"),
17  "field_1_2" => $ui->input()->field()->text("Item 1.2", "Just some other field")
18  ],
19  "Switchable Group number one (with numeric key)"
20  );
21  $group2 = $ui->input()->field()->group(
22  [
23  "field_2_1" => $ui->input()->field()->text("Item 2", "Just another field")
24  ->withValue('some val')
25  ],
26  "Switchable Group number two"
27  );
28  $group3 = $ui->input()->field()->group([], 'No items in this group');
29 
30  //Step 2: Switchable Group - one or the other:
31  $sg = $ui->input()->field()->switchableGroup(
32  [
33  "1" => $group1,
34  "g2" => $group2,
35  "g3" => $group3
36  ],
37  "Pick One",
38  "...or the other"
39  );
40 
41  $form = $ui->input()->container()->form()->standard(
42  '#',
43  [
44  'switchable_group' => $sg,
45  //A group like the first, with different Label and Byline and
46  //g2 selected by default.
47  'switchable_group2' => $sg->withValue("g2")
48  ->withLabel("Again, Pick One")
49  ->withByline("... or the other.
50  Note, the second option is selected by default here.")
51  ]
52  );
53 
54  //Step 3: implement some form data processing.
55  if ($request->getMethod() == "POST") {
56  $form = $form->withRequest($request);
57  $result = $form->getData();
58  } else {
59  $result = "No result yet.";
60  }
61 
62  //Step 4: Render.
63  return
64  "<pre>" . print_r($result, true) . "</pre><br/>" .
65  $renderer->render($form);
66 }
$result
base()
Definition: base.php:4
$DIC
Definition: xapitoken.php:46