? files
? patches
? sites/all/modules
Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.161
diff -U3 -r1.161 form.inc
--- includes/form.inc	26 Nov 2006 22:35:20 -0000	1.161
+++ includes/form.inc	29 Nov 2006 18:50:30 -0000
@@ -884,7 +884,7 @@
   $size = $element['#size'] ? ' size="' . $element['#size'] . '"' : '';
   _form_set_class($element, array('form-select'));
   $multiple = isset($element['#multiple']) && $element['#multiple'];
-  return theme('form_element', $element, '<select name="'. $element['#name'] .''. ($multiple ? '[]' : '') .'"'. ($multiple ? ' multiple="multiple" ' : '') . drupal_attributes($element['#attributes']) .' id="'. $element['#id'] .'" '. $size .'>'. form_select_options($element) .'</select>');
+  return theme('form_element', $element, '<select name="'. $element['#name'] .''. ($multiple ? '[]' : '') .'"'. ($multiple ? ' multiple="multiple" ' : '') . drupal_attributes($element['#attributes']) .' id="'. form_clean_id($element['#id']) .'" '. $size .'>'. form_select_options($element) .'</select>');
 }

 function form_select_options($element, $choices = NULL) {
@@ -1188,7 +1188,7 @@
   $checkbox = '<input ';
   $checkbox .= 'type="checkbox" ';
   $checkbox .= 'name="'. $element['#name'] .'" ';
-  $checkbox .= 'id="'. $element['#id'].'" ' ;
+  $checkbox .= 'id="'. form_clean_id($element['#id']).'" ' ;
   $checkbox .= 'value="'. $element['#return_value'] .'" ';
   $checkbox .= $element['#value'] ? ' checked="checked" ' : ' ';
   $checkbox .= drupal_attributes($element['#attributes']) . ' />';
@@ -1262,7 +1262,7 @@
  *   A themed HTML string representing the hidden form field.
  */
 function theme_hidden($element) {
-  return '<input type="hidden" name="'. $element['#name'] . '" id="'. $element['#id'] . '" value="'. check_plain($element['#value']) ."\" " . drupal_attributes($element['#attributes']) ." />\n";
+  return '<input type="hidden" name="'. $element['#name'] . '" id="'. form_clean_id($element['#id']) . '" value="'. check_plain($element['#value']) ."\" " . drupal_attributes($element['#attributes']) ." />\n";
 }

 function theme_token($element) {
@@ -1287,7 +1287,7 @@
   if ($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'], NULL, NULL, TRUE)) .'" disabled="disabled" />';
+    $extra =  '<input class="autocomplete" type="hidden" id="'. form_clean_id($element['#id']) .'-autocomplete" value="'. check_url(url($element['#autocomplete_path'], NULL, NULL, TRUE)) .'" disabled="disabled" />';
   }
   _form_set_class($element, $class);

@@ -1295,7 +1295,7 @@
     $output .= '<span class="field-prefix">'. $element['#field_prefix'] .'</span> ';
   }

-  $output .= '<input type="text" maxlength="'. $element['#maxlength'] .'" name="'. $element['#name'] .'" id="'. $element['#id'] .'" '. $size .' value="'. check_plain($element['#value']) .'"'. drupal_attributes($element['#attributes']) .' />';
+  $output .= '<input type="text" maxlength="'. $element['#maxlength'] .'" name="'. $element['#name'] .'" id="'. form_clean_id($element['#id']) .'" '. $size .' value="'. check_plain($element['#value']) .'"'. drupal_attributes($element['#attributes']) .' />';

   if (isset($element['#field_suffix'])) {
     $output .= ' <span class="field-suffix">'. $element['#field_suffix'] .'</span>';
@@ -1316,7 +1316,7 @@
 function theme_form($element) {
   // Anonymous div to satisfy XHTML compliance.
   $action = $element['#action'] ? 'action="' . check_url($element['#action']) . '" ' : '';
-  return '<form '. $action . ' method="'. $element['#method'] .'" '. 'id="'. $element['#id'] .'"'. drupal_attributes($element['#attributes']) .">\n<div>". $element['#children'] ."\n</div></form>\n";
+  return '<form '. $action . ' method="'. $element['#method'] .'" '. 'id="'. form_clean_id($element['#id']) .'"'. drupal_attributes($element['#attributes']) .">\n<div>". $element['#children'] ."\n</div></form>\n";
 }

 /**
@@ -1337,7 +1337,7 @@

   $cols = $element['#cols'] ? ' cols="'. $element['#cols'] .'"' : '';
   _form_set_class($element, $class);
-  return theme('form_element', $element, '<textarea'. $cols .' rows="'. $element['#rows'] .'" name="'. $element['#name'] .'" id="'. $element['#id'] .'" '. drupal_attributes($element['#attributes']) .'>'. check_plain($element['#value']) .'</textarea>');
+  return theme('form_element', $element, '<textarea'. $cols .' rows="'. $element['#rows'] .'" name="'. $element['#name'] .'" id="'. form_clean_id($element['#id']) .'" '. drupal_attributes($element['#attributes']) .'>'. check_plain($element['#value']) .'</textarea>');
 }

 /**
@@ -1370,7 +1370,7 @@
   $maxlength = $element['#maxlength'] ? ' maxlength="'. $element['#maxlength'] .'" ' : '';

   _form_set_class($element, array('form-text'));
-  $output = '<input type="password" name="'. $element['#name'] .'" id="'. $element['#id'] .'" '. $maxlength . $size . drupal_attributes($element['#attributes']) .' />';
+  $output = '<input type="password" name="'. $element['#name'] .'" id="'. form_clean_id($element['#id']) .'" '. $maxlength . $size . drupal_attributes($element['#attributes']) .' />';
   return theme('form_element', $element, $output);
 }

@@ -1467,7 +1467,7 @@
   if (isset($element['#attributes']['class'])) {
     $class[] = $element['#attributes']['class'];
   }
-  $element['#attributes']['class'] = implode(' ', $class);
+  $element['#attributes']['class'] = form_clean_class(implode(' ', $class));
 }

 /**
@@ -1479,10 +1479,23 @@
  *   The cleaned ID
  */
 function form_clean_id($id = NULL) {
-  $id = str_replace('][', '-', $id);
+  $id = str_replace(array('][', '_'), '-', $id);
   return $id;
 }

 /**
+ * Remove invalid characters from an HTML CLASS attribute string.
+ *
+ * @param $class
+ *   The CLASS to clean
+ * @return
+ *   The cleaned CLASS
+ */
+function form_clean_class($class = NULL) {
+  $class = str_replace('_', '-', $class);
+  return $class;
+}
+
+/**
  * @} End of "defgroup form".
  */