diff --git a/app/src/Service/Forms/Form.php b/app/src/Service/Forms/Form.php index 70326b3..3ea5bc7 100644 --- a/app/src/Service/Forms/Form.php +++ b/app/src/Service/Forms/Form.php @@ -16,8 +16,7 @@ class Form public readonly string $name, public readonly string $method, public readonly string $action - ) { - } + ) { } public function output(): string { @@ -26,16 +25,30 @@ class Form return $doc->saveHTML($this->form); } - protected function addElement(string $type, array $properties): DOMElement + /** + * Helper method for adding an element to the Form. + * + * @param string $type The type of element to add + * @param array $properties Proprties for the element + * @return DOMElement + */ + protected function addElement(string $type, array $properties = []): DOMElement { $elem = new DOMElement($type); - foreach ($properties as $attr => $value) { - $elem->setAttribute($attr, $value); - } + if (!empty($properties)) { + foreach ($properties as $attr => $value) { + $elem->setAttribute($attr, $value); + } + } return $elem; } + /** + * @param string $name + * @param array $properties + * @return satic + */ public function addInput(string $name, array $properties = []): static { $input = $this->addElement('input', [