Skip to content

Commit 9cf5907

Browse files
author
Christian Leucht
committed
Form // fixing bug where non-existing fields in data array caused to overwrite existing field values (defaults) with empty values.
1 parent fbc016f commit 9cf5907

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Element/Form.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ public function withData(array $data = []): static
6262
throw new LogicException('You cannot change data of a submitted form.');
6363
}
6464

65-
foreach ($this->elements() as $name => $element) {
66-
$value = $data[$name] ?? '';
67-
$this->rawData[$name] = $value;
68-
65+
foreach ($data as $name => $value) {
66+
if (!$this->elementExists($name)) {
67+
continue;
68+
}
69+
$element = $this->element($name);
6970
$element->withValue($value);
7071
$this->data[$name] = $element->value();
7172
}

0 commit comments

Comments
 (0)