Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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)?
Thanks!
Clint
Comments
Comment #1
apadernoComment #2
kaakuu CreditAttribution: kaakuu commented+1
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.
Comment #3
markus_petrux CreditAttribution: markus_petrux commentedThe 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}.
Comment #4
justclint CreditAttribution: justclint commentedThanks for the response. So what is the recommended solution for this? Should I just change to TEXT, TINYTEXT, BLOB, etc...
Comment #5
justclint CreditAttribution: justclint commentedAfter 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?
Comment #6
justclint CreditAttribution: justclint commentedOk, so I just went into firebug to check the input field and saw this:
So I guess thats the problem. How do we fix this so I can get all 255 characters allowed by the table.
Comment #7
justclint CreditAttribution: justclint commentedComment #8
kaakuu CreditAttribution: kaakuu commentedIdeal 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;
add
$content = str_replace("maxlength=\"128\"", "maxlength=\"250\"", $content);
Comment #9
justclint CreditAttribution: justclint commentedKaakuu 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!
Comment #10
justclint CreditAttribution: justclint commentedWell 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?
Comment #11
apadernoThere is surely a validation function that checks the length of the used labels.
Comment #12
kaakuu CreditAttribution: kaakuu commentedThe code that does that seems to be in includes/form.inc
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
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.
Comment #13
markus_petrux CreditAttribution: markus_petrux commentedThe 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.
Comment #14
justclint CreditAttribution: justclint commentedThanks 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:
includes/locale.inc
includes/path.admin.inc
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:
Comment #15
apaderno@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.
Comment #16
justclint CreditAttribution: justclint commentedWill do. Thanks Kiamlaluno!
Comment #17
justclint CreditAttribution: justclint commentedHey 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:
3. Created file called label_maxlength.module and inserted in this file:
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!
Comment #18
danielb CreditAttribution: danielb commentedIf 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.
Comment #20
neojohan CreditAttribution: neojohan commentedDoes this work for Drupal 7?
Comment #22
zeta1600 CreditAttribution: zeta1600 commentedNeojohan... did you get this to work in D7?
Comment #23
alirezaara CreditAttribution: alirezaara commentedThe module does not work for D7.
Does anyone have any suggestion?
Comment #24
kenorb CreditAttribution: kenorb commentedDrupal 7 separate issue:
#1645368: How do you increase the maximum length for labels in Drupal 7?
Comment #25
maximpodorov CreditAttribution: maximpodorov commentedNew module:
http://drupal.org/project/remove_field_label_length_limit
Comment #26
timmay CreditAttribution: timmay commentedToo bad it takes a module to fix this, but this worked perfectly for me.
Thanks.
Comment #28
new123456789 CreditAttribution: new123456789 commentedIs there a better solution to this?
Comment #29
new123456789 CreditAttribution: new123456789 commentedfixed - https://drupal.org/project/remove_field_label_length_limit
Comment #30
it_mohit CreditAttribution: it_mohit commentedFor 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;
Comment #31
bshensky CreditAttribution: bshensky commented#17 worked plenty fine for us in D6.