Skip to content

Commit

Permalink
Form: fix setting values from post during error handling (42851)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmitz-ilias committed Nov 21, 2024
1 parent 23d2238 commit 1f4ef43
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions components/ILIAS/Form/classes/class.ilDateDurationInputGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,14 @@ public function render(): string
// values

$out_format = $this->getDatetimeFormatForInput();
$date_value = htmlspecialchars($this->invalid_input_start);
$date_value = $this->prepareInvalidInputAsValue($this->invalid_input_start);
if (!$date_value &&
$this->getStart()) {
$date_value = $this->getStart()->get(IL_CAL_FKT_DATE, $out_format, $ilUser->getTimeZone());
}
$tpl->setVariable('DATEPICKER_START_VALUE', $date_value);

$date_value = htmlspecialchars($this->invalid_input_end);
$date_value = $this->prepareInvalidInputAsValue($this->invalid_input_end);
if (!$date_value &&
$this->getEnd()) {
$date_value = $this->getEnd()->get(IL_CAL_FKT_DATE, $out_format, $ilUser->getTimeZone());
Expand All @@ -438,6 +438,15 @@ public function render(): string
return $tpl->get();
}

protected function prepareInvalidInputAsValue(string $invalid_input): string
{
$timestamp = strtotime(htmlspecialchars($invalid_input));
if ($timestamp === false) {
return '';
}
return date($this->getDatetimeFormatForInput(), $timestamp);
}


public function insert(ilTemplate $a_tpl): void
{
Expand Down

0 comments on commit 1f4ef43

Please sign in to comment.