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