Since Drupal 5.11. form fields are wrapped by divs with ids. (Patch was committed to 5.x here: http://drupal.org/node/181831)
But there are at least two issues with this:
1. While the 'id' of the element now gets added a 'wrapper' the 'label for' doesn't. So in html we get a "reference to non-existent ID" error here.
2. Up to now there are no individual ids for each single radio-button. Every radio-button in a set of radio-buttons has the same id. So we get an "ID already defined" error here.
This patch fixes both problems by
- adding a 'wrapper' to the 'label for' in function theme_form_element and
- adding the '#return_value' to the id of a radio-button in function form_builder.
I am not sure if these are the right places to do this changes. But for me it works fine and the html-errors are gone.
Please feel free to change this patch for the better.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 344317.patch | 1.06 KB | robloach |
| form_ids.patch | 1.31 KB | smitty |
Comments
Comment #1
smitty commentedComment #2
robloachThe labels do have the "for" attribute, they don't have an ID, however. Drupal 7 doesn't have the ID labels, so it'll have to go in there first.
Comment #3
robloachI also noticed an extra < div > being added right after the form element....
Comment #4
jroth commentedI think I have a solution that doesn't include modifying core files...
Placing the following code in my template.php file seems to do the trick.
function phptemplate_form_element($element, $value) {
if (!empty($element['#id'])) {static $dupe_ids = array();
$output = '
$dupe_ids[$element['#id']]++;
$output .= ' id="'. $element['#id'] .'-wrapper-'.$dupe_ids[$element['#id']].'"';
}
$output .= ">\n";
$required = !empty($element['#required']) ? '*' : '';
if (!empty($element['#title'])) {
$title = $element['#title'];
if (!empty($element['#id'])) {
$output .= ' '. t('!title: !required', array('!title' => filter_xss_admin($title), '!required' => $required)) ."\n";
}
else {
$output .= ' '. t('!title: !required', array('!title' => filter_xss_admin($title), '!required' => $required)) ."\n";
}
}
$output .= " $value\n";
if (!empty($element['#description'])) {
$output .= '
\n";
}
$output .= "
\n";
return $output;
}
Comment #5
smitty commentedNevertheless I think that's a bug in the core and should be fixed there.
Comment #6
sunIs this still an issue? Form labels and checkboxes/radios have been revamped in the meantime.
Comment #7
robloachI'd consider #495480: Add class to wrapper div of form elements theme_form() a better solution. Labels are also now stuck in a theme function, not sure what else you'd like to do with them.
Comment #8
sunNot sure how that issue is related to this issue.
This is the only part of this issue which may be still valid under certain conditions.
This is no longer the case in D7.
Comment #9
robloachHmmm, maybe it's just a wrapper element that's missing then?
Comment #11
sunWas that a confirmation that the issue/problem still exists?