Accessible Comment Forms in Textpattern

    6 July 2004, early evening

A question was posed on the textpattern forum on how one can set up the comment forms in textpattern so they are more accessible. What follows is how I went about doing so.

I basically followed the advice outlined by Mark Pilgrim on his Dive into Accessibility site. Day 28 on his site discusses labelling form elements.

There is a textpattern form called comments_form that is used to display the html form used to get comments from the user. (I now see why people objected to calling forms forms.) You should edit that so that the fields: name, email, http, and message, are all enclosed in label tags. You should also attach a for attribute to each of these labels.

You will then have to edit the textpattern source code so that the form elements are generated with id values, not just name values. You will have to edit the publish.php file, and the /publish/comments.php files to add id attributes to the form elements that are generated.

In publish.php, find the line:


'<input type="'.$type.'" name="'.$name.'" value="'.$val.'"',

and change it to


'<input type="'.$type.'" id="'.$name.'" name="'.$name.'" value="'.$val.'"',

In /publish/comments.php, find the line:


$textarea = '<textarea name="message" cols="1" rows="1" style="width:300px;height:250px" tabindex="4">'.htmlspecialchars($message).'</textarea>';

and change it to


$textarea = '<textarea id="message" name="message" cols="1" rows="1" style="width:300px;height:250px" tabindex="4">'.htmlspecialchars($message).'</textarea>';

The remember and forget check-boxes are generated by <txp:comment_remember />, so you willl have to edit /lib/txplib_forms.php and change line 114 from:


$o[] = '<input type="checkbox" name="'.$name.'" value="'.$value.'"';

To:


$o[] = '<input type="checkbox" id="'.$name.'" name="'.$name.'" value="'.$value.'"';

And then in /publish/comments.php change:


$checkbox = (!empty($_COOKIE['txp_name']))
    ?checkbox('forget',1,0).gTxt('forget')
    :checkbox('remember',1,1).gTxt('remembe');

to:


$checkbox = (!empty($_COOKIE['txp_name']))
    ?checkbox('forget',1,0).gTxt('<label for="forget">forget</label>')
    :checkbox('remember',1,1).gTxt('<label for="remember">remember</label>');

 

Comments

Don't be shy, you can comment too!

 
Some things to keep in mind: You can style comments using Textile. In particular, *text* will get turned into text and _text_ will get turned into text. You can post a link using the command "linktext":link, so something like "google":http://www.google.com will get turned in to google. I may erase off-topic comments, or edit poorly formatted comments; I do this very rarely.