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

vigo - January 19, 2007 - 15:02

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...

joancatala - January 20, 2007 - 15:43

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

vigo - January 21, 2007 - 02:23

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

joancatala - January 22, 2007 - 09:16

Thanks Vigo, I will try on the 5.0 version :)

cheers!

Glad to help

vigo - January 22, 2007 - 11:56

Glad to help

Poll is not accessible!

hunthunthunt - June 13, 2007 - 17:06

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:

11.3 Labeling form controls

Checkpoints in this section:

  • 12.4 Associate labels explicitly with their controls. [Priority 2]
  • 10.2 Until user agents support explicit associations between labels and form controls, for all form controls with implicitly associated labels, ensure that the label is properly positioned. [Priority 2]

An example of LABEL used with "for" in HTML 4.01 is given in the previous section.

A label is implicitly associated with its form control either through markup or positioning on the page. The following example shows how a label and form control may be implicitly associated with markup.

Example.

   <LABEL for="firstname">First name:
     <INPUT type="text" id="firstname" tabindex="1">
   </LABEL>

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

hunthunthunt - June 15, 2007 - 16:48

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

valeria78 - June 20, 2007 - 11:14

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?

hunthunthunt - June 25, 2007 - 10:41

So that:

themename_radio

would become:

valeriastheme_radio

or whatever the name of the theme you are using?

Actually no.... I'll do it

valeria78 - June 26, 2007 - 07:04

Actually no....
I'll do it and post if it works.
Thanks!

I did name the function with

valeria78 - June 26, 2007 - 07:16

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

hunthunthunt - June 26, 2007 - 09:06

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

valeria78 - June 27, 2007 - 09:52

Maybe that's why: I have the 4.7.6!

 
 

Drupal is a registered trademark of Dries Buytaert.