From ec8bb01dc80df7d26a47b140792238842236d5a5 Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Mon, 28 Jul 2025 22:27:49 -0400 Subject: [PATCH] Work on the Form class. --- app/src/Service/Forms/Form.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) 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', [