5

How can I remove the : from appearing after every label in forms made with the Drupal Form API?

4 Answers 4

13

Create your own implementation of theme_form_element(). The offending semicolon is in $t('!title: !required', ...), and would need to be removed in both locations.

Not the easiest thing to change, but at least it's possible without hacking core!

1

The way I've just done it is to add a <span class="colon"><span> around the colon in field.tpl.php. Then I can hide it with display:none; if I don't want it.

It avoids putting a lot of logic into a tpl.php if you have multiple fields which either need or don't need colons.

It also allows you to change fields colon requirements on different pages. For example I often don't want them on displaying a node but would like them in editing.

0

copy the field.tpl.php to your current theme folder and remove colon. Clear cache and check. I think It will solve the problem.

-2

You can try this also, works for me in drupal 7.

Drop this in the body of your version of 'page.tpl.php' in your template folder.

<?php
    drupal_add_js(
      'jQuery(document).ready(function () {
        var labels = jQuery(".field-label");
        jQuery.each(labels, function() {
          this.innerHTML = this.innerHTML.replace(":", "");
        });
      });',
      'inline');
  ?>
3
  • Why was this voted down? Is it a valid way to remove the colons or not?
    – blue928
    May 31, 2012 at 6:27
  • 1
    It was probably voted down because it's a client-side only solution. It would be far preferable to do this on the server side, as in Tim's answer
    – Clive
    May 31, 2012 at 11:28
  • Note that this removes that character everywhere, and not only after the label
    – Pere
    Jun 23, 2014 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.