Hey Guys, Im doing this questionnaire and some of my field labels need to be 1 or 2 sentences long. I noticed I can only insert x amount of characters in when creating the field title.

How can I increase the max length for the field title (labels)?




kiamlaluno’s picture

Title: maxlength for lables??? How to increase??? » How do you increase the maximum length for labels?
kaakuu’s picture


I will also like to know. Each field (in a CMS) whether in core or contributed needs to have a min and max possible values which can be set by the super Admin.

markus_petrux’s picture

Status: Active » Fixed

The size of the field labels is limited by the size of the database column that is used to store its value, which is varchar(255). See table {content_node_field_instance}.

justclint’s picture

Thanks for the response. So what is the recommended solution for this? Should I just change to TEXT, TINYTEXT, BLOB, etc...

justclint’s picture

After going back and looking at some of my labels for my fields I noticed that its only letting me insert 128 character (including spaces) but my label field in {content_node_field_instance} is varchar(255) as you mentioned above.

Any thoughts?

justclint’s picture

Ok, so I just went into firebug to check the input field and saw this:

<input type="text" class="form-text" value="" size="15" id="edit--add-new-field-label" name="_add_new_field[label]" maxlength="128"/>

So I guess thats the problem. How do we fix this so I can get all 255 characters allowed by the table.

justclint’s picture

Status: Fixed » Needs review
kaakuu’s picture

Ideal will be admin interface that lets min and max possible values to be set by the super Admin. This should in fact be a core feature of a good CMS.

Dirty hack will be - open your page.tpl.php in your theme folder in a text editor, and
Before this
print $content;
$content = str_replace("maxlength=\"128\"", "maxlength=\"250\"", $content);

justclint’s picture

Status: Needs review » Fixed

Kaakuu you are a life save! Thanks so much!!!

I couldn't find anything in admin so I just did the dirty hack and it worked like a charm.

Thanks again!

justclint’s picture

Status: Fixed » Needs review

Well I have made the input maxlength 255 but when I go to submit the field I still cant do it and I get this error:

"Label cannot be longer than 128 characters but is currently 172 characters long."

How do I fix this?

kiamlaluno’s picture

There is surely a validation function that checks the length of the used labels.

kaakuu’s picture

The code that does that seems to be in includes/form.inc

       // Verify that the value is not longer than #maxlength.
      if (isset($elements['#maxlength']) && drupal_strlen($elements['#value']) > $elements['#maxlength']) {
        form_error($elements, $t('!name cannot be longer than %max characters but is currently %length characters long.', array('!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'], '%max' => $elements['#maxlength'], '%length' => drupal_strlen($elements['#value']))));

So, one way to dirty-fix that (no idea of the consequences, whether it will break security and/or site, and perhaps need back-up or keeping the file still open in text editor and undo in case of problem) will be
comment that so it is not executed

       // Verify that the value is not longer than #maxlength.
   /*   if (isset($elements['#maxlength']) && drupal_strlen($elements['#value']) > $elements['#maxlength']) {
        form_error($elements, $t('!name cannot be longer than %max characters but is currently %length characters long.', array('!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'], '%max' => $elements['#maxlength'], '%length' => drupal_strlen($elements['#value']))));
      } */ 

As I said before this needs to be an administrative interface feature of a CMS that really allows me to 'manage' my content - so best thing will be to submit an usability issue request at the issues lists of project Drupal.

markus_petrux’s picture

Status: Needs review » Fixed

The great thing inDrupal is that you do not need to hack here and there to do almost anything. You just need to find the hook that suits your needs better.

In this case, use hook_form_alter() for this purpose.

justclint’s picture

Status: Fixed » Needs review

Thanks Markus!

Ok so Im trying this hook_form_alter but as Im new Drupal and have not used this function yet so Im not sure if I got it right.

I know the syntax is "module_form_alter". I also did a search for 128 in my directory and found

"'#maxlength' => 128," in both:

I could be wrong but I think one of those is what I want to hook. Not sure how to do this since Im not using my own custom module, form was just made in CCK, I came up with this but doesnt seem to be working:

//in my template.php: 
  function cck_form_alter(&$form, $form_state, $form_id) {

    switch ($form_id) {
      case 'my-form':
$form['my-form'] = array('#type' => 'textfield',
    '#maxlength' => 225,
kiamlaluno’s picture

@justclint: It doesn't seem you are looking into the directory of CCK, as CCK doesn't have those files.
What is the not correct in your code is that you are using for the field ID the form ID; it's improbable that both the ID use the same value. Also, the code should just change the value of the array index #maxlength, not all the form field array.

I suggest you to ask for help in IRC.

justclint’s picture

Status: Needs review » Fixed

Will do. Thanks Kiamlaluno!

justclint’s picture

Hey Guys, finally got this working. Ive never written module before but I found fix at http://drupal.org/node/233905 on post #15.

Took that info and read the drupal api a bit and did the following in case it helps anyone else especially some newbie like me.

1. I created a folder called label_maxlength in my sites/all/modules directory.

2. Created file called label_maxlength.info and inserted in this file:

; $Id: label_maxlength.module Exp $

name = "Label Maxlength"
description = "Module to change label maxlength from 128 to 255."
core = 6.x

3. Created file called label_maxlength.module and inserted in this file:

function label_maxlength_form_alter(&$form, $form_state, $form_id) {
    if($form_id == 'content_field_overview_form'){
        $form['_add_new_field']['label']['#maxlength'] = 255;
        $form['_add_existing_field']['label']['#maxlength'] = 255;
    else if($form_id == 'content_field_edit_form'){
        $form['basic']['label']['#maxlength'] = 255;

NOTE: Do not include php closing tag.

Then just went to modules page to install and it worked both for adding a field and editing a field!

I just want to say thank you again guys for your support and direction!

danielb’s picture

If you want labels longer than 255, you could use the 255 to store a shortened identifier, and use a custom table, or variable_set, to store a corresponding longer replacement value that you can substitute back in with hooks.

Status: Fixed » Closed (fixed)

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

neojohan’s picture

Does this work for Drupal 7?

zeta1600’s picture

Neojohan... did you get this to work in D7?

alirezaara’s picture

The module does not work for D7.
Does anyone have any suggestion?

kenorb’s picture

maximpodorov’s picture

timmay’s picture

Too bad it takes a module to fix this, but this worked perfectly for me.

new123456789’s picture

Is there a better solution to this?

new123456789’s picture

it_mohit’s picture

For drupal 6 users

Use this in form alter don't touch the drupal core. you can use this globally in form alter to change the form alter if you need on particular form use that conditionally

$form['label']['#maxlength'] = 255;

bshensky’s picture

#17 worked plenty fine for us in D6.