I know this one has been bothering Matt for a long time. He's even submitted a core patch for it. But nothing has gotten in yet due to translation problems.
However I ran into this problem again while putting together our new contact form (using the amazing Webform Module). I decided to solve it in our theme and thought others might want to use this trick.
By copying the theme_form_element() function from the theme.inc and pasting it into our template.php file, we can do a little checking to see if the form element title ends with a punctuation character. And if so, suppress the trailing colon.
Here's what it looks like for Drupal 4.7. I'm guessing it'll be pretty similar, if not completely the same for Drupal 5:
/**
* Rewrite of theme_form_element() to suppress ":" if the title ends with a punctuation mark.
*/
function phptemplate_form_element($title, $value, $description = NULL, $id = NULL, $required = FALSE, $error = FALSE) {
$output = ''."\n";
$required = $required ? '*' : '';
if ($title) {
// I've added the next two lines
$punctuation = array(',', '.', '?', '!', ':');
$colon = in_array($title[strlen($title)-1], $punctuation) ? '' : ':';
if ($id) {
// I've modified this next bit
$output .= ' '
. t('%title%colon %required', array('%title' => $title, '%required' => $required, '%colon' => $colon))
. "\n";
}
else {
// and this one too
$output .= ' '
. t('%title%colon %required', array('%title' => $title, '%required' => $required, '%colon' => $colon))
. "\n";
}
}
$output .= " $value\n";
if ($description) {
$output .= ' '. $description ."\n";
}
$output .= "\n";
return $output;
}
Sorry about the weird output. Some of the lines are a bit long.