login/edit: build input html from prepared attributes
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 16 Jun 2018 21:30:33 +0000 (23:30 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 16 Jun 2018 21:37:07 +0000 (23:37 +0200)
Same results, easier to maintain.

login/edit.php

index 4e52506bdf839fdb0699c00cd1bf4b5de3212cb2..6dfbfab5caf8f6ac00f563ad06c8ea9f40604278 100644 (file)
@@ -124,18 +124,32 @@ foreach ($cols as $col => &$colconf) {
                        200, $colconf['target'], filemtime($colconf['target'])
                );
        }
-       print "<input";
-       if (empty($colconf['target'])) print ' readonly';
-       printf(' type="%s" name="%s" id="%2$s" value="%s"',
-               @$colconf['type'] ?: 'text',
-               $col,
-               htmlspecialchars(@$colconf['value'])
-       );
-       if (@$colconf['type'] == 'file') {
-               printf(' accept="%s"', 'image/jpeg');
+
+       {
+               $attrs = [
+                       'type'        => @$colconf['type'] ?: 'text',
+                       'name'        => $col,
+                       'id'          => $col,
+                       'value'       => htmlspecialchars(@$colconf['value']),
+                       'placeholder' => "Niet ingesteld",
+                       'readonly'    => empty($colconf['target']),
+               ];
+               if (@$colconf['type'] == 'file') {
+                       $attrs['accept'] = "image/jpeg";
+               }
+
+               print '<input';
+               foreach ($attrs as $attr => $attrval) {
+                       if ($attrval === FALSE) {
+                               continue;
+                       }
+                       print ' ' . $attr;
+                       if ($attrval !== TRUE) {
+                               printf('="%s"', $attrval);
+                       }
+               }
+               print ' />';
        }
-       print ' placeholder="Niet ingesteld"';
-       print " />";
 
        if ($error = @$colwarn[$col]) {
                print " <span class=warn>$error</span>\n";