ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
base.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
30 function base()
31 {
32  //Step 0: Declare dependencies
33  global $DIC;
34 
35  $ui = $DIC->ui()->factory();
36  $renderer = $DIC->ui()->renderer();
37  $request = $DIC->http()->request();
38  $ctrl = $DIC->ctrl();
39 
40 
41  //Step 1: define the input
42  $duration = $ui->input()->field()->duration("Pick a time-span", "This is the byline text");
43  $timezone = $duration
44  ->withTimezone('America/El_Salvador')
45  ->withUseTime(true)
46  ->withByline('timezone and both time and date');
47 
48  $time = $duration->withTimeOnly(true)->withRequired(true)->withLabels('start time', 'end time');
49 
50  //Step 2: define form and form actions, attach the input
51  $form = $ui->input()->container()->form()->standard(
52  '#',
53  [
54  'duration' => $duration,
55  'time' => $time,
56  'timezone' => $timezone,
57  'disabled' => $duration->withLabel('disabled')->withDisabled(true)
58  ]
59  );
60 
61  $result = "";
62 
63  //Step 3: implement some form data processing.
64  if ($request->getMethod() == "POST") {
65  $form = $form->withRequest($request);
66  $groups = $form->getInputs();
67  foreach ($groups as $group) {
68  if ($group->getError()) {
69  $result = $group->getError();
70  } else {
71  //The result is sumarized through the transformation
72  $result = $form->getData();
73  }
74  }
75  } else {
76  $result = "No result yet.";
77  }
78 
79  //Step 4: Render the form.
80  return
81  "<pre>" . print_r($result, true) . "</pre><br/>" .
82  $renderer->render($form);
83 }
base()
description: > Base example showing how to plug date-inputs into a form.
Definition: base.php:30
$renderer
$duration
global $DIC
Definition: shib_login.php:25