I have created a form using the form api (drupal 6.x), and after the title for each of the form elements, it adds a colon. For example, I am calling a form element like this:

$form['questionnaire']['howmuchmoney'] = array
(
	'#type' => 'select',
	'#title' => t('How much money do you have allocated?'),
	'#required' => TRUE,
	'#options' => array
	(
		'$500 OR LESS' => '$500 OR LESS',
		// etc
	)
);

And the title appears like this on the page:

How much money do you have allocated?:

This looks strange having a colon and a question mark. Does anybody know how to remove this question mark? It seems that drupal is adding extra unwanted text to my form, and I'm hoping there is an override for it!

Comments

jaypan’s picture

bump

Contact me to contract me for D7 -> D10/11 migrations.

nevets’s picture

The colon comes from theme_form_element() which you can override.

jaypan’s picture

Thank you sir!

Edit: I was able to override this and get rid of the colons. Thanks again!

Contact me to contract me for D7 -> D10/11 migrations.

flavor’s picture

what did you do to remove the :

I.E how did you override this ?

jkopel’s picture

I am late to the party, but I had the same problem.
I not only wanted to remove the : after ?, but also in other spots where it did not make sense.
In those cases I add a ~ char to the end of the title (using a hook_form_alter() if necessary) and then remove the ~ later when I strip the : in the theme function.

Here is my solution (stylistic criticism appreciated):

function YOURTHEMENAME_form_element($element, $value) {
  // This is also used in the installer, pre-database setup.
  $t = get_t();

  $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'];
      // we are going to substitute a blank for the colon if:
      // the title has a ~ at the end (allows you to hide the colon arbitrarily, and then we remove the ~)
      // the title has a ? at the end
	$colon = ':';
	switch(TRUE){
		case  (strrpos($title, "~")+1 == strlen($title)):
			$title = substr($title,0,strrpos($title,'~'));
		case  (strrpos($title, "?")+1 == strlen($title)):
			$colon =  "";
  			break; 
 	}
    if (!empty($element['#id'])) {
      $output .= ' <label for="'. $element['#id'] .'">'. $t('!title!colon !required', array('!title' => filter_xss_admin($title), '!colon' => $colon, '!required' => $required)) ."</label>\n";
    }
    else {
      $output .= ' <label>'. $t('!title!colon !required', array('!title' => filter_xss_admin($title), '!colon' => $colon, '!required' => $required)) ."</label>\n";
    }
  }

  $output .= " $value\n";

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

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

  return $output;
}
shark’s picture

If you just want to hide the colon after the question mark, this simple code will do that (replaces the switch(TRUE) statement in the code above):

if (!empty($element['#title'])) {
    $title = $element['#title'];

    $colon = ':';
    // If title ends in ?, don't print colon after it.
    if ($title[strlen($title)-1] == '?') {
      $colon = '';
    }

...
Sinan Erdem’s picture

http://drupal.org/project/no_colons

This module works for almost all titles (views, CCK, form API, etc...).