Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.448
diff -u -r1.448 form.inc
--- includes/form.inc	4 Apr 2010 13:22:51 -0000	1.448
+++ includes/form.inc	6 Apr 2010 10:38:29 -0000
@@ -1925,10 +1925,20 @@
  */
 function theme_select($variables) {
   $element = $variables['element'];
-  $size = $element['#size'] ? ' size="' . $element['#size'] . '"' : '';
+  $attributes = array(
+    'name' => $element['#name'],
+    'id' => $element['#id'],
+  );
+  if ($element['#size']) {
+    $attributes['size'] = $element['#size'];
+  }
+  if ($element['#multiple']) {
+    $attributes['name'] .= '[]';
+    $attributes['multiple'] = 'multiple';
+  }
+
   _form_set_class($element, array('form-select'));
-  $multiple = $element['#multiple'];
-  return '<select name="' . $element['#name'] . '' . ($multiple ? '[]' : '') . '"' . ($multiple ? ' multiple="multiple" ' : '') . drupal_attributes($element['#attributes']) . ' id="' . $element['#id'] . '" ' . $size . '>' . form_select_options($element) . '</select>';
+  return '<select' . drupal_attributes($attributes + $element['#attributes']) . '>' . form_select_options($element) . '</select>';
 }
 
 /**
@@ -2076,15 +2086,18 @@
  */
 function theme_radio($variables) {
   $element = $variables['element'];
-  _form_set_class($element, array('form-radio'));
-  $output = '<input type="radio" ';
-  $output .= 'id="' . $element['#id'] . '" ';
-  $output .= 'name="' . $element['#name'] . '" ';
-  $output .= 'value="' . $element['#return_value'] . '" ';
-  $output .= (check_plain($element['#value']) == $element['#return_value']) ? ' checked="checked" ' : ' ';
-  $output .= drupal_attributes($element['#attributes']) . ' />';
+  $attributes = array(
+    'type' => 'radio',
+    'id' => $element['#id'],
+    'name' => $element['#name'],
+    'value' => $element['#return_value'],
+  );
+  if (check_plain($element['#value']) == $element['#return_value']) {
+    $attributes['checked'] = 'checked';
+  }
 
-  return $output;
+  _form_set_class($element, array('form-radio'));
+  return '<input' . drupal_attributes($attributes + $element['#attributes']) . " />\n";
 }
 
 /**
@@ -2319,20 +2332,19 @@
  */
 function theme_checkbox($variables) {
   $element = $variables['element'];
-  $t = get_t();
-  _form_set_class($element, array('form-checkbox'));
-  $checkbox = '<input ';
-  $checkbox .= 'type="checkbox" ';
-  $checkbox .= 'name="' . $element['#name'] . '" ';
-  $checkbox .= 'id="' . $element['#id'] . '" ' ;
-  $checkbox .= 'value="' . $element['#return_value'] . '" ';
+  $attributes = array(
+    'type' => 'checkbox',
+    'name' => $element['#name'],
+    'id' => $element['#id'],
+    'value' => $element['#return_value']
+  );
   // Unchecked checkbox has #value of numeric 0.
   if ($element['#value'] !== 0 && $element['#value'] == $element['#return_value']) {
-    $checkbox .= 'checked="checked" ';
+    $attributes['checked'] = 'checked';
   }
-  $checkbox .= drupal_attributes($element['#attributes']) . ' />';
 
-  return $checkbox;
+  _form_set_class($element, array('form-checkbox'));
+  return '<input' . drupal_attributes($attributes + $element['#attributes']) . " />\n";
 }
 
 /**
@@ -2774,7 +2786,16 @@
   $element = $variables['element'];
   $element['#attributes']['class'][] = 'form-' . $element['#button_type'];
 
-  return '<input type="submit" ' . (empty($element['#name']) ? '' : 'name="' . $element['#name'] . '" ') . 'id="' . $element['#id'] . '" value="' . check_plain($element['#value']) . '" ' . drupal_attributes($element['#attributes']) . " />\n";
+  $attributes = array(
+    'type' => 'submit',
+    'id' => $element['#id'],
+    'value' => $element['#value']
+  );
+  if (!empty($element['#name'])) {
+    $attributes['name'] = $element['#name'];
+  }
+
+  return '<input' . drupal_attributes($attributes + $element['#attributes']) . " />\n";
 }
 
 /**
@@ -2793,13 +2814,21 @@
   $element = $variables['element'];
   $element['#attributes']['class'][] = 'form-' . $element['#button_type'];
 
-  return '<input type="image" name="' . $element['#name'] . '" ' .
-    (!empty($element['#value']) ? ('value="' . check_plain($element['#value']) . '" ') : '') .
-    'id="' . $element['#id'] . '" ' .
-    drupal_attributes($element['#attributes']) .
-    ' src="' . file_create_url($element['#src']) . '" ' .
-    (!empty($element['#title']) ? 'alt="' . check_plain($element['#title']) . '" title="' . check_plain($element['#title']) . '" ' : '' ) .
-    "/>\n";
+  $attributes = array(
+    'type' => 'image',
+    'name' => $element['#name'],
+    'id' => $element['#id'],
+    'src' => file_create_url($element['#src'])
+  );
+  if (!empty($element['#value'])) {
+    $attributes['value'] = $element['#value'];
+  }
+  if (!empty($element['#title'])) {
+    $attributes['alt'] = $element['#title'];
+    $attributes['title'] = $element['#title'];
+  }
+
+  return '<input' . drupal_attributes($attributes + $element['#attributes']) . " />\n";
 }
 
 /**
@@ -2817,7 +2846,15 @@
  */
 function theme_hidden($variables) {
   $element = $variables['element'];
-  return '<input type="hidden" name="' . $element['#name'] . '" id="' . $element['#id'] . '" value="' . check_plain($element['#value']) . "\" " . drupal_attributes($element['#attributes']) . " />\n";
+
+  $attributes = array(
+    'type' => 'hidden',
+    'name' => $element['#name'],
+    'id' => $element['#id'],
+    'value' => $element['#value']
+  );
+
+  return '<input' . drupal_attributes($attributes + $element['#attributes']) . " />\n";
 }
 
 /**
@@ -2836,22 +2873,30 @@
  */
 function theme_textfield($variables) {
   $element = $variables['element'];
-  $size = empty($element['#size']) ? '' : ' size="' . $element['#size'] . '"';
-  $maxlength = empty($element['#maxlength']) ? '' : ' maxlength="' . $element['#maxlength'] . '"';
+
+  $attributes = array(
+    'type' => 'text',
+    'name' => $element['#name'],
+    'id' => $element['#id'],
+    'value' => $element['#value'],
+  );
+  if (!empty($element['#maxlength'])) {
+    $attributes['maxlength'] = $element['#maxlength'];
+  }
+  if (!empty($element['#size'])) {
+    $attributes['size'] = $element['#size'];
+  }
+
   $class = array('form-text');
   $extra = '';
-  $output = '';
-
   if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) {
     drupal_add_js('misc/autocomplete.js');
     $class[] = 'form-autocomplete';
-    $extra =  '<input class="autocomplete" type="hidden" id="' . $element['#id'] . '-autocomplete" value="' . check_url(url($element['#autocomplete_path'], array('absolute' => TRUE))) . '" disabled="disabled" />';
+    $extra = '<input class="autocomplete" type="hidden" id="' . $element['#id'] . '-autocomplete" value="' . check_url(url($element['#autocomplete_path'], array('absolute' => TRUE))) . '" disabled="disabled" />';
   }
-  _form_set_class($element, $class);
-
-  $output .= '<input type="text"' . $maxlength . ' name="' . $element['#name'] . '" id="' . $element['#id'] . '"' . $size . ' value="' . check_plain($element['#value']) . '"' . drupal_attributes($element['#attributes']) . ' />';
 
-  return $output . $extra;
+  _form_set_class($element, $class);
+  return '<input' . drupal_attributes($attributes + $element['#attributes']) . ' />' . $extra . "\n";
 }
 
 /**
@@ -2869,9 +2914,17 @@
  */
 function theme_form($variables) {
   $element = $variables['element'];
+
+  $attributes = array();
+  if ($element['#action']) {
+    $attributes['action'] = check_url($element['#action']);
+  }
+  $attributes['accept-charset'] = 'UTF-8';
+  $attributes['method'] = $element['#method'];
+  $attributes['id'] = $element['#id'];
+
   // Anonymous div to satisfy XHTML compliance.
-  $action = $element['#action'] ? 'action="' . check_url($element['#action']) . '" ' : '';
-  return '<form ' . $action . ' accept-charset="UTF-8" method="' . $element['#method'] . '" id="' . $element['#id'] . '"' . drupal_attributes($element['#attributes']) . ">\n<div>" . $element['#children'] . "\n</div></form>\n";
+  return '<form' . drupal_attributes($attributes + $element['#attributes']) . ">\n<div>" . $element['#children'] . "\n</div></form>\n";
 }
 
 /**
@@ -2890,24 +2943,28 @@
  */
 function theme_textarea($variables) {
   $element = $variables['element'];
+
+  $attributes = array(
+    'cols' => $element['#cols'],
+    'rows' => $element['#rows'],
+    'name' => $element['#name'],
+    'id' => $element['#id'],
+  );
+
   $wrapper_attributes = array(
     'class' => array('form-textarea-wrapper'),
   );
   $class = array('form-textarea');
-
   // Add resizable behavior.
   if (!empty($element['#resizable'])) {
     drupal_add_js('misc/textarea.js');
     $wrapper_attributes['class'][] = 'resizable';
   }
 
-  $output = '<div' . drupal_attributes($wrapper_attributes) . '>';
-
   _form_set_class($element, $class);
-  $output .= '<textarea cols="' . $element['#cols'] . '" rows="' . $element['#rows'] . '" name="' . $element['#name'] . '" id="' . $element['#id'] . '" ' . drupal_attributes($element['#attributes']) . '>' . check_plain($element['#value']) . '</textarea>';
-
-  $output .= '</div>';
-  return $output;
+  return '<div' . drupal_attributes($wrapper_attributes) . '>'
+    . '<textarea' . drupal_attributes($attributes + $element['#attributes']) . '>' . check_plain($element['#value']) . '</textarea>'
+    . '</div>';
 }
 
 /**
@@ -2926,12 +2983,21 @@
  */
 function theme_password($variables) {
   $element = $variables['element'];
-  $size = $element['#size'] ? ' size="' . $element['#size'] . '" ' : '';
-  $maxlength = $element['#maxlength'] ? ' maxlength="' . $element['#maxlength'] . '" ' : '';
+
+  $attributes = array(
+    'type' => 'password',
+    'name' => $element['#name'],
+    'id' => $element['#id'],
+  );
+  if (!empty($element['#maxlength'])) {
+    $attributes['maxlength'] = $element['#maxlength'];
+  }
+  if (!empty($element['#size'])) {
+    $attributes['size'] = $element['#size'];
+  }
 
   _form_set_class($element, array('form-text'));
-  $output = '<input type="password" name="' . $element['#name'] . '" id="' . $element['#id'] . '" ' . $maxlength . $size . drupal_attributes($element['#attributes']) . ' />';
-  return $output;
+  return '<input' . drupal_attributes($attributes + $element['#attributes']) . " />\n";
 }
 
 /**
@@ -2967,8 +3033,16 @@
  */
 function theme_file($variables) {
   $element = $variables['element'];
+
+  $attributes = array(
+    'type' => 'file',
+    'name' => $element['#name'],
+    'id' => $element['#id'],
+    'size' => $element['#size'],
+  );
+
   _form_set_class($element, array('form-file'));
-  return '<input type="file" name="' . $element['#name'] . '"' . ($element['#attributes'] ? ' ' . drupal_attributes($element['#attributes']) : '') . ' id="' . $element['#id'] . '" size="' . $element['#size'] . "\" />\n";
+  return '<input' . drupal_attributes($attributes + $element['#attributes']) . " />\n";
 }
 
 /**
