I must be confused, because this couldn't POSSSIBLY be a bug. But:
I was trying to get some textfields working properly: they were inside a fieldset in a multi-step form, and were failing to pick up the default value I was trying to give them. I eventually checked the definition of theme_textfield, and found this:
function theme_textfield($element) {
$size = $element['#size'] ? ' size="' . $element['#size'] . '"' : '';
$class = array('form-text');
$extra = '';
$output = '';
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" />';
}
_form_set_class($element, $class);
if (isset($element['#field_prefix'])) {
$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']) .' />';
if (isset($element['#field_suffix'])) {
$output .= ' <span class="field-suffix">'. $element['#field_suffix'] .'</span>';
}
return theme('form_element', $element, $output). $extra;
}
That is, there's no reference to the element's #default_value -- only its #value. I defined my own theme_textfield function that changes the line in question to:
$output .= '<input type="text" maxlength="'. $element['#maxlength'] .'" name="'. $element['#name'] .'" id="'. $element['#id'] .'" '. $size .' value="'. check_plain($element['#default_value']) .'"'. drupal_attributes($element['#attributes']) .' />';
and everything now seems to be working properly, both in the fieldset that was causing me problems and in other forms and textfields as well.
Am I missing something here? I can't believe that this has existed as a bug for all this time, but the code as it exists neither works nor (to my limited understanding of the gory details of the forms api) makes sense. I'm now worried that I've fixed one thing but broken many others, which I won't discover until it's too later. Can anyone put my mind to rest?