Poll not respecting W3C accesibility
joancatala - January 19, 2007 - 12:24
I'm using a Poll and it is not accesibly as the W3C says because the labels does not contain the parametrer "for=xxxx".
Here you are an example:
<LABEL for="valencia">bla,bla:
<INPUT type="text" id="valencia" tabindex="1">
</LABEL>Does anyone knows how can I add or modify the parametrer for="valencia" on the labels of the pollls?

Label wrapping input is OK
If the label element wraps the input then that is perfect fine, there is a semantic relationship between the two. So, no accessibility problems there.
The large accessibility problem with your sample code is the tabindex attribute. Tabindex is out-dated, generally pointless, dangerous and actually harms accessibility unless you put it on every link and input on the page.
language problems...
Sorry, I didn't explain good because english is not my mother language...
This example is what I would like to have... but the poll doesn't creates this kind of tags...
This exemple is accesible for W3C... but the poll doesn't. Don't you have a poll on your site? You just have to try it and you'll see what I'm telling.
No problem in 5.0
I've just created a poll using Drupal 5.0 in the default Garland theme it outputs this code for each choice:
<div class="form-item"><label class="option"><input type="radio" name="choice" value="0" class="form-radio" /> choice one</label>
</div>
This is perfectly accessible and W3C compliant.
Because the label element surrounds the input element they are related and there is no accessibility problem.
all rigth
Thanks Vigo, I will try on the 5.0 version :)
cheers!
Glad to help
Glad to help
Poll is not accessible!
Joancatla is correct, vigo statements are misleading. Poll is not accessible in it's current format. Wrapping an input field with it's label does not make it accessible, see example from the W3C:
from: http://www.w3.org/TR/WCAG10-HTML-TECHS/#forms-labels
For more detailed information see:
http://www.w3.org/TR/2007/WD-WCAG20-TECHS-20070517/Overview.html#H44
My fix
Looking in to this, the problem is with form.inc not the poll module.
Fortunately you are able to theme the relevant function using template.php.
My solution is as follows:
function themename_radio($element) {
// Create a random number to append to the ID
//This is required as with e.g. poll mudule, the poll
// node appears twice resulting in duplicate IDs
$new_rand_no = (mt_rand(10,1000000));
_form_set_class($element, array('form-radio'));
$output = '<input type="radio" ';
$output .= 'name="' . $element['#name'] .'" ';
$output .= 'value="'. $element['#return_value'] .'" ';
$output .= 'id="'. $element['#id'] . '_' . $element['#return_value'] . $new_rand_no .'" ';
$output .= (check_plain($element['#value']) == $element['#return_value']) ? ' checked="checked" ' : ' ';
$output .= drupal_attributes($element['#attributes']) .' />';
if (!is_null($element['#title'])) {
$output = '<label class="option" for="' . $element['#id'] . '_' . $element['#return_value'] . $new_rand_no .'">'. $output .' '. $element['#title'] .'</label>';
}
unset($element['#title']);
return theme('form_element', $element, $output);
}
Hope this helps
I have the same problem with
I have the same problem with the Simplenews module. I copy-pasted hunthunthunt's patch to the template.php, but it is not working.
Can anybody help me, please?
did you change the theme name?
So that:
themename_radio
would become:
valeriastheme_radio
or whatever the name of the theme you are using?
Actually no.... I'll do it
Actually no....
I'll do it and post if it works.
Thanks!
I did name the function with
I did name the function with the name of the theme I'm using. When I upload the modified template.php, above the radio buttons I get an "Array: " label, clearly displaying on my web page, which is not exactly what I want, and of course it doesn't pass the WCAG priority 2 test.
What could I do?
I see that the functions in my template.php are name "phptemplate_functionName". May it be this the error?
Thanks again!
That is odd
I don't understand why the array is being output.
I should have mentioned, my code snippet is for drupal 5.1
Maybe that's why: I have the
Maybe that's why: I have the 4.7.6!