|
7 | 7 | */
|
8 | 8 | class FormLib
|
9 | 9 | {
|
| 10 | + public static $default_class = ''; |
10 | 11 |
|
11 | 12 | public static function __callStatic($name, $arguments)
|
12 | 13 | {
|
@@ -86,6 +87,9 @@ public static function submit($value, $attributes = [])
|
86 | 87 | */
|
87 | 88 | public static function text($name, $value, $attributes = [])
|
88 | 89 | {
|
| 90 | + if (!isset($attributes['class']) and '' != self::$default_class) { |
| 91 | + $attributes['class'] = self::$default_class; |
| 92 | + } |
89 | 93 | return self::input('text', $name, $value, $attributes);
|
90 | 94 | }
|
91 | 95 |
|
@@ -138,6 +142,10 @@ public static function radio($name, $value, $attributes = [])
|
138 | 142 | */
|
139 | 143 | public static function select($name, $value, $options, $attributes = [])
|
140 | 144 | {
|
| 145 | + if (!isset($attributes['class']) and '' != self::$default_class) { |
| 146 | + $attributes['class'] = self::$default_class; |
| 147 | + } |
| 148 | + |
141 | 149 | $html = sprintf(
|
142 | 150 | '<select id="%s" name="%s"%s>',
|
143 | 151 | $name,
|
@@ -189,11 +197,13 @@ public static function textarea($name, $value, $attributes = [])
|
189 | 197 | public static function attributesToHtml($attributes)
|
190 | 198 | {
|
191 | 199 | $html = '';
|
192 |
| - foreach ($attributes as $attribute => $attribute_value) { |
193 |
| - if (true === $attribute_value) { |
194 |
| - $attribute_value = $attribute; |
| 200 | + if (is_array($attributes)) { |
| 201 | + foreach ($attributes as $attribute => $attribute_value) { |
| 202 | + if (true === $attribute_value) { |
| 203 | + $attribute_value = $attribute; |
| 204 | + } |
| 205 | + $html .= sprintf(' %s="%s"', $attribute, htmlspecialchars($attribute_value)); |
195 | 206 | }
|
196 |
| - $html .= sprintf(' %s="%s"', $attribute, htmlspecialchars($attribute_value)); |
197 | 207 | }
|
198 | 208 | return $html;
|
199 | 209 | }
|
|
0 commit comments