ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
base.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
10 function base()
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 
22  //Step 1: define the input
23  $duration = $ui->input()->field()->duration("Pick a time-span", "This is the byline text");
24  $timezone = $duration
25  ->withTimezone('America/El_Salvador')
26  ->withUseTime(true)
27  ->withByline('timezone and both time and date');
28 
29  $time = $duration->withTimeOnly(true)->withRequired(true)->withLabels('start time', 'end time');
30 
31  //Step 2: define form and form actions, attach the input
32  $form = $ui->input()->container()->form()->standard(
33  '#',
34  [
35  'duration' => $duration,
36  'time' => $time,
37  'timezone' => $timezone,
38  'disabled' => $duration->withLabel('disabled')->withDisabled(true)
39  ]
40  );
41 
42  $result = "";
43 
44  //Step 3: implement some form data processing.
45  if ($request->getMethod() == "POST") {
46  $form = $form->withRequest($request);
47  $groups = $form->getInputs();
48  foreach ($groups as $group) {
49  if ($group->getError()) {
50  $result = $group->getError();
51  } else {
52  //The result is sumarized through the transformation
53  $result = $form->getData();
54  }
55  }
56  } else {
57  $result = "No result yet.";
58  }
59 
60  //Step 4: Render the form.
61  return
62  "<pre>" . print_r($result, true) . "</pre><br/>" .
63  $renderer->render($form);
64 }
base()
Base example showing how to plug date-inputs into a form.
Definition: base.php:10
global $DIC
Definition: feed.php:28