Skip to content

Commit

Permalink
fix(datefield,datetimefield): avoid PHP warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <[email protected]>
  • Loading branch information
btry committed Jan 28, 2020
1 parent 9233628 commit 90f8259
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 10 additions & 2 deletions inc/fields/datefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function getRenderedHtml($canEdit = true) {
if (!$canEdit) {
return $this->value;
}

$html = '';
$id = $this->question->getID();
$rand = mt_rand();
Expand Down Expand Up @@ -164,12 +164,20 @@ public function lessThan($value) {
}

public function parseAnswerValues($input, $nonDestructive = false) {

$key = 'formcreator_field_' . $this->question->getID();
if (!isset($input[$key])) {
$input[$key] = '';
}

if (!is_string($input[$key])) {
return false;
}

if ($input[$key] != ''
&& DateTime::createFromFormat("Y-m-d", $input[$key]) === false) {
return false;
}

$this->value = $input[$key];
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions inc/fields/datetimefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ public function lessThan($value) {

public function parseAnswerValues($input, $nonDestructive = false) {
$key = 'formcreator_field_' . $this->question->getID();
if (!isset($input[$key])) {
$input[$key] = '';
}
if (!is_string($input[$key])) {
return false;
}
Expand Down

0 comments on commit 90f8259

Please sign in to comment.