Browse Source

Add `addTextInput` and `addSelect` methods that are simpler than `addInput`

master^2
Skylar Ittner 2 months ago
parent
commit
26a662c399
1 changed files with 35 additions and 0 deletions
  1. 35
    0
      lib/FormBuilder.lib.php

+ 35
- 0
lib/FormBuilder.lib.php View File

@@ -116,6 +116,41 @@ class FormBuilder {
116 116
         $this->items[] = $item;
117 117
     }
118 118
 
119
+    /**
120
+     * Add a text input.
121
+     *
122
+     * @param string $name Element name
123
+     * @param string $value Element value
124
+     * @param bool $required If the element is required for form submission.
125
+     * @param string $id Element ID
126
+     * @param string $label Text label to display near the input
127
+     * @param string $icon FontAwesome icon (example: "fas fa-toilet-paper")
128
+     * @param int $width Bootstrap column width for the input, out of 12.
129
+     * @param int $minlength Minimum number of characters for the input.
130
+     * @param int $maxlength Maximum number of characters for the input.
131
+     * @param string $pattern Regex pattern for custom client-side validation.
132
+     * @param string $error Message to show if the input doesn't validate.
133
+     */
134
+    public function addTextInput(string $name, string $value = "", bool $required = true, string $id = "", string $label = "", string $icon = "", int $width = 4, int $minlength = 1, int $maxlength = 100, string $pattern = "", string $error = "") {
135
+        $this->addInput($name, $value, "text", $required, $id, null, $label, $icon, $width, $minlength, $maxlength, $pattern, $error);
136
+    }
137
+
138
+    /**
139
+     * Add a select dropdown.
140
+     *
141
+     * @param string $name Element name
142
+     * @param string $value Element value
143
+     * @param bool $required If the element is required for form submission.
144
+     * @param string $id Element ID
145
+     * @param array $options Array of [value => text] pairs for a select element
146
+     * @param string $label Text label to display near the input
147
+     * @param string $icon FontAwesome icon (example: "fas fa-toilet-paper")
148
+     * @param int $width Bootstrap column width for the input, out of 12.
149
+     */
150
+    public function addSelect(string $name, string $value = "", bool $required = true, string $id = null, array $options = null, string $label = "", string $icon = "", int $width = 4) {
151
+        $this->addInput($name, $value, "select", $required, $id, $options, $label, $icon, $width);
152
+    }
153
+
119 154
     /**
120 155
      * Add a button to the form.
121 156
      *

Loading…
Cancel
Save