I have a text field, with filtered HTML and a max length of 2500 characters. The problem is that when I count the characters numbers, it is under 2500 characters but when I want to save my node, I get an error message which says that "the value may not be longer than 2500 characters."

For a text field with filtered HTML, how characters are counted ? Are HTML tags considered as characters ?

Comments

rolando.isidoro’s picture

Hi lucuhb,

I've stumbled upon the same problem you described. I looked into the CCK's source code and from what I could tell HTML tags are considered too:

// Line 159 @ cck/modules/text/text.module
if (!empty($field['max_length']) && drupal_strlen($item['value']) > $field['max_length']) {

To prevent this from happening a simple workaround can be implemented, just by using PHP's strip_tags function:

// Line 159 @ cck/modules/text/text.module
if (!empty($field['max_length']) && drupal_strlen(strip_tags($item['value'])) > $field['max_length']) {

Even though this solves your problem, I wouldn't advise you to change the source code. Maybe we could ask for this to be an optional setting on the field definition screen, so we could op-out the HTML tags from the char limit count.

Rolando

lucuhb’s picture

Category: support » feature

Yes, this could be a good idea to have a specific parameter to define whether or not HTML tags are integrated in the character count

NewZeal’s picture

I third this request. I don't like having to hack modules, and while cck is integrated into D7, D6 still has a lot of life left in it. OK, so I admit it, I'm hacking this module and using it on a production site :)

baisong’s picture

Also using this hack on a production site...