Base example showing how to plug date-inputs into a form.
6{
7
8
10
11 $ui =
$DIC->ui()->factory();
13 $renderer =
$DIC->ui()->renderer();
14 $request =
$DIC->http()->request();
16
17
18 $date = $ui->input()->field()->dateTime("Pick a date/time", "This is the byline text");
19 $formatted = $date
20 ->withMinValue(new DateTimeImmutable())
21 ->withFormat(
$data->dateFormat()->germanShort());
22 $time = $date->withTimeOnly(true);
23 $both = $date->withUseTime(true);
24
25
26 $tz = 'Asia/Tokyo';
27 $timezoned = $both->withTimezone($tz)->withByline('Result-value will have TZ ' . $tz);
28
29
30 $date_now = new DateTime('now');
31 $date_zoned = new DateTime('now', new \DateTimeZone($tz));
32
33
34
35 $format = $timezoned->getFormat()->toString() .
' H:i';
36 $timezoned_preset1 = $timezoned->withValue($date_now->format(
$format))
37 ->withByline('This is local "now"');
38 $timezoned_preset2 = $timezoned->withValue($date_zoned->format(
$format))
39 ->withByline('This is "now" in ' . $tz);
40
41
42 $form = $ui->input()->container()->form()->standard('#', [
43 'date' => $date,
44 'formatted' => $formatted,
45 'time' => $time,
46 'both' => $both,
47 'timezoned' => $timezoned,
48 'timezoned_preset1' => $timezoned_preset1,
49 'timezoned_preset2' => $timezoned_preset2,
50 'disabled' => $date
51 ->withValue($date_now->format(
$format))
52 ->withLabel('disabled')
53 ->withDisabled(true)
54 ]);
55
56
57 if ($request->getMethod() == "POST") {
58 $form = $form->withRequest($request);
60 } else {
62 }
63
64
65 return
66 "<pre>" . print_r(
$result,
true) .
"</pre><br/>" .
67 $renderer->render($form);
68}