diff --git a/src/Element/Form.php b/src/Element/Form.php index a245fa3..6e3004e 100644 --- a/src/Element/Form.php +++ b/src/Element/Form.php @@ -62,10 +62,11 @@ public function withData(array $data = []): static throw new LogicException('You cannot change data of a submitted form.'); } - foreach ($this->elements() as $name => $element) { - $value = $data[$name] ?? ''; - $this->rawData[$name] = $value; - + foreach ($data as $name => $value) { + if (!$this->elementExists($name)) { + continue; + } + $element = $this->element($name); $element->withValue($value); $this->data[$name] = $element->value(); }