login/edit: build input html from prepared attributes
[minimedit.git] / login / edit.php
index 9611c7d8ba85a5cb25d820ff8f7c74a3f443e13e..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";
@@ -144,13 +158,19 @@ foreach ($cols as $col => &$colconf) {
 }
 
 if (isset($user['pass'])) {
-       $hide = empty($_POST['newpass']);
 ?>
-       <li id="pass"<?php if ($hide) print ' hidden style="display:none"'; ?>>
-               <label for="newpass">Wachtwoord:</label>
-               <input type="password" name="oldpass" value="" placeholder="Huidig wachtwoord" />
-               <input type="password" name="newpass" value="" placeholder="Nieuw wachtwoord" />
-               <input type="password" name="passconf" value="" placeholder="Nogmaals" />
+       <li><label for="newpass">Wachtwoord:</label>
+<?php
+       if ($hide = empty($_POST['newpass'])) {
+?>
+               <a onclick="document.getElementById('pass').removeAttribute('hidden'); this.remove()">Wijzigen</a>
+<?php
+       }
+?>
+               <span id="pass"<?php if ($hide) print ' hidden'; ?>>
+                       <input type="password" name="oldpass" value="" placeholder="Huidig wachtwoord" />
+                       <input type="password" name="newpass" value="" placeholder="Nieuw wachtwoord" />
+                       <input type="password" name="passconf" value="" placeholder="Nogmaals" />
 <?php
        if ($error = @$colwarn['pass']) {
                print " <span class=warn>$error</span>\n";
@@ -161,12 +181,5 @@ if (isset($user['pass'])) {
 }
 ?>
        </ul>
-       <input type="submit" value="Opslaan" />
+       <p><input type="submit" value="Opslaan" /></p>
 </form>
-
-<?php
-       if ($hide) {
-?>
-       <p><a onclick="document.getElementById('pass').removeAttribute('style'); this.remove()">Wachtwoord wijzigen</a></p>
-<?php
-       }