diff --git a/inc/common.php b/inc/common.php
index 6ea6d56d8e0f5b30deab4250aa9bb44e778eba27..b4866bccf7338e29995523e913cf64623476505b 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -242,13 +242,16 @@ function buildURLparams($params, $sep='&'){
  */
 function buildAttributes($params,$skipempty=false){
     $url = '';
+    $white = false;
     foreach($params as $key => $val){
         if($key{0} == '_') continue;
         if($val === '' && $skipempty) continue;
+        if($white) $url .= ' ';
 
         $url .= $key.'="';
         $url .= htmlspecialchars ($val);
-        $url .= '" ';
+        $url .= '"';
+        $white = true;
     }
     return $url;
 }
diff --git a/inc/form.php b/inc/form.php
index e614d2f30df29fc4555eaf04d3fab6b2a0d95038..30e16b626cf7954f715385ca1e6217dceb5dab1f 100644
--- a/inc/form.php
+++ b/inc/form.php
@@ -696,7 +696,7 @@ function form_wikitext($attrs) {
  */
 function form_button($attrs) {
     $p = (!empty($attrs['_action'])) ? 'name="do['.$attrs['_action'].']" ' : '';
-    return '<input '.$p.buildAttributes($attrs,true).'/>';
+    return '<input '.$p.buildAttributes($attrs,true).' />';
 }
 
 /**
@@ -714,7 +714,7 @@ function form_field($attrs) {
     if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
     if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
     $s .= '><span>'.$attrs['_text'].'</span>';
-    $s .= ' <input '.buildAttributes($attrs,true).'/></label>';
+    $s .= ' <input '.buildAttributes($attrs,true).' /></label>';
     if (preg_match('/(^| )block($| )/', $attrs['_class']))
         $s .= '<br />';
     return $s;
@@ -734,7 +734,7 @@ function form_fieldright($attrs) {
     $s = '<label';
     if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
     if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
-    $s .= '><input '.buildAttributes($attrs,true).'/>';
+    $s .= '><input '.buildAttributes($attrs,true).' />';
     $s .= ' <span>'.$attrs['_text'].'</span></label>';
     if (preg_match('/(^| )block($| )/', $attrs['_class']))
         $s .= '<br />';
@@ -758,7 +758,7 @@ function form_textfield($attrs) {
     if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
     if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
     $s .= '><span>'.$attrs['_text'].'</span> ';
-    $s .= '<input type="text" '.buildAttributes($attrs,true).'/></label>';
+    $s .= '<input type="text" '.buildAttributes($attrs,true).' /></label>';
     if (preg_match('/(^| )block($| )/', $attrs['_class']))
         $s .= '<br />';
     return $s;
@@ -781,7 +781,7 @@ function form_passwordfield($attrs) {
     if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
     if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
     $s .= '><span>'.$attrs['_text'].'</span> ';
-    $s .= '<input type="password" '.buildAttributes($attrs,true).'/></label>';
+    $s .= '<input type="password" '.buildAttributes($attrs,true).' /></label>';
     if (preg_match('/(^| )block($| )/', $attrs['_class']))
         $s .= '<br />';
     return $s;
@@ -807,7 +807,7 @@ function form_filefield($attrs) {
     $s .= '<input type="file" '.buildAttributes($attrs,true);
     if (!empty($attrs['_maxlength'])) $s .= ' maxlength="'.$attrs['_maxlength'].'"';
     if (!empty($attrs['_accept'])) $s .= ' accept="'.$attrs['_accept'].'"';
-    $s .= '/></label>';
+    $s .= ' /></label>';
     if (preg_match('/(^| )block($| )/', $attrs['_class']))
         $s .= '<br />';
     return $s;
@@ -837,7 +837,7 @@ function form_checkboxfield($attrs) {
                  . ' value="' . hsc($attrs['value'][1]) . '" />';
         $attrs['value'] = $attrs['value'][0];
     }
-    $s .= '<input type="checkbox" '.buildAttributes($attrs,true).'/>';
+    $s .= '<input type="checkbox" '.buildAttributes($attrs,true).' />';
     $s .= ' <span>'.$attrs['_text'].'</span></label>';
     if (preg_match('/(^| )block($| )/', $attrs['_class']))
         $s .= '<br />';
@@ -860,7 +860,7 @@ function form_radiofield($attrs) {
     $s = '<label';
     if ($attrs['_class']) $s .= ' class="'.$attrs['_class'].'"';
     if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
-    $s .= '><input type="radio" '.buildAttributes($attrs,true).'/>';
+    $s .= '><input type="radio" '.buildAttributes($attrs,true).' />';
     $s .= ' <span>'.$attrs['_text'].'</span></label>';
     if (preg_match('/(^| )block($| )/', $attrs['_class']))
         $s .= '<br />';