hi all, i'm trying to get rid of the colon (:) at the end of a question. I want to put a question survey with a question mark (?) at the end. It won't look funny if the label looks like this

How satisfy are you with our products?:

Somebody guide me how to remove the symbol, colon (:) please?

Thanks.

Comments

suit4’s picture

this can be done globally only, that means for all form elements!

override theme_form_element, e.g.put this in your template.php

function phptemplate_form_element($element, $value) {
  $output  = '<div class="form-item">'."\n";
  $required = !empty($element['#required']) ? '<span class="form-required" title="'. t('This field is required.') .'">*</span>' : '';

  if (!empty($element['#title'])) {
    $title = $element['#title'];
    if (!empty($element['#id'])) {
      $output .= ' <label for="'. $element['#id'] .'">'. t('!title !required', array('!title' => filter_xss_admin($title), '!required' => $required)) ."</label>\n";
    }
    else {
      $output .= ' <label>'. t('!title !required', array('!title' => filter_xss_admin($title), '!required' => $required)) ."</label>\n";
    }
  }

  $output .= " $value\n";

  if (!empty($element['#description'])) {
    $output .= ' <div class="description">'. $element['#description'] ."</div>\n";
  }

  $output .= "</div>\n";

  return $output;
}

the colon comes from these lines:

 $output .= ' <label for="'. $element['#id'] .'">'. t('!title: !required', array('!title' => filter_xss_admin($title), '!required' => $required)) 

you need to remove the colon after !title!

hope that helps

seakayjay’s picture

Status: Active » Fixed

thank you so much. the code works.

mandclu’s picture

I was able to selectively remove the colons after question marks by changing the function as follows:

function phptemplate_form_element($element, $value) {
  $output  = '<div class="form-item">'."\n";
  $required = !empty($element['#required']) ? '<span class="form-required" title="'. t('This field is required.') .'">*</span>' : '';

  if (!empty($element['#title'])) {
    $title = $element['#title'];
    if (strcmp(substr($title,-1),'?') != 0) {
      $separator = ':';
    }
    if (!empty($element['#id'])) {
      $output .= ' <label for="'. $element['#id'] .'">'. t('!title'. $separator .' !required', array('!title' => $title, '!required' => $required)) ."</label>\n";
    }
    else {
      $output .= ' <label>'. t('!title'. $separator .' !required', array('!title' => $title, '!required' => $required)) ."</label>\n";
    }
  }

  $output .= " $value\n";

  if (!empty($element['#description'])) {
    $output .= ' <div class="description">'. $element['#description'] ."</div>\n";
  }

  $output .= "</div>\n";

  return $output;
}
suit4’s picture

hmm, nice idea,

but in general users should be able to set questionmarks, colons or whatever as they need them. this shouldn't be hardcoded. maybe the drupal core needs a wrapper class for its own form labels.

mandclu’s picture

I guess the only thing I can say is that for the sake of consistency there is something to be said for having the end character added automatically.

Another approach would be to allow admin settings for the final character, and the also allow characters to be specified following which the character should not appear. Wouldn't be a crazy amount of work, though perhaps overkill for most users. The nice thing, though, would be that could maintain the current behaviour but allow for savvy users to make their installations more complicated, to meet their needs.

I know in French they tend to prefer a space before the colon, so maybe better terminology would be label suffix, and it should accept more than a single character.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

citronica’s picture

@surge_martin:

Thanks! This still works in Drupal 6.10.

decibel.places’s picture

this did not work for me on webform labels

I devised a DHTML method http://drupal.org/node/293908/1540580

suit4’s picture

Title: How to remove colon (:) at the end of a question? » How to remove punctuation from the end of a form field label?

To remove other types of punctuation from the end of field labels, the theme function can easily be altered like this:

function phptemplate_form_element($element, $value) {
	// This is also used in the installer, pre-database setup.
	$t = get_t();
	$separator= ($element['#title'] && preg_match("/[!?.:]$/", $element['#title']) != 0) ? '' : ':';
	$output = '<div class="form-item"';
	if (!empty($element['#id'])) {
		$output .= ' id="'. $element['#id'] .'-wrapper"';
	}
	$output .= ">\n";
	$required = !empty($element['#required']) ? '<span class="form-required" title="'. $t('This field is required.') .'">*</span>' : '';

	if (!empty($element['#title'])) {
		$title = $element['#title'];
		if (!empty($element['#id'])) {
			$output .= ' <label for="'. $element['#id'] .'">'. $t('!title'. $separator . ' !required', array('!title' => filter_xss_admin($title), '!required' => $required)) ."</label>\n";
		}
		else {
			$output .= ' <label>'. $t('!title: !required', array('!title' => filter_xss_admin($title), '!required' => $required)) ."</label>\n";
		}
	}

	$output .= " $value\n";

	if (!empty($element['#description'])) {
		$output .= ' <div class="description">'. $element['#description'] ."</div>\n";
	}

	$output .= "</div>\n";

	return $output;
}

This works in D6 as well.

christefano’s picture

I've noticed that the approach in #9 doesn't work if the form element is a select widget.

alex.pilon’s picture

Nice to have a default though..