Posted by gcassie on March 3, 2007 at 5:46pm
I looked around, but it seems all the posts on this subject deal with 4.x, and I'm running 5.1.
I would like to add an accesskey (S, specifically) to my comment's "submit comment" button. I tried adding '#accesskey' => 'S' to the comment.module code of that button, sort of hoping that would work, but it doesn't. Does anyone know how to accomplish this? I don't mind hacking at core.
I recognize the debate around the viability of accesskeys, but I just moved over from a phpbb forum and a lot of users miss hitting "alt-s" to submit their posts.
If you like, you can see what I've got going so far at www.rollinitiative.com . Thank you for your help.
Comments
I'm not happy with the
I'm not happy with the method, but I got this working.
I'm using the Garland theme, and added this code to template.php:
<?phpfunction phptemplate_comment_form($form) {
return str_replace('value="Post comment"','accesskey="S" value="Submit comment"',drupal_render($form));
}
?>
Works, but I know it's doing more string processing than I want it to be. Ah well. Perhaps someone will find this useful.
accesskey with hook_form_alter
Another approach is to use hook_form_alter in a custom module.
By using a function similar to the one shown below, you should be able to add accesskey as an attribute to the the submit button.
// add accesskey "S" to submit button on comment_form and forum_node_formfunction yourmodule_form_alter($form_id, &$form) {
if ( ($form_id == 'comment_form') || ($form_id == 'forum_node_form') ) {
if (is_null($form['submit']['#attributes'])) {
$form['submit']['#attributes'] = array('accesskey' => 's');
}
else {
$form['submit']['#attributes']['accesskey'] = 's';
}
}
}
I threw this together to as an experiment, so it isn't well tested. Replace "yourmodule" with the name of your custom module.
You might also want to look at this contributed module: http://drupal.org/project/hotkey