The autocomplete form of the taxonomy module
limits the max characters to 255, regardless of the actual underlying limits

$form['taxonomy']['tags'][$vocabulary->vid] = array('#type' => 'textfield',
'#title' => $vocabulary->name,
'#description' => $help,
'#required' => $vocabulary->required,
'#default_value' => $typed_string,
'#autocomplete_path' => 'taxonomy/autocomplete/'. $vocabulary->vid,
'#weight' => $vocabulary->weight,
'#maxlength' => 255,
);

this means we cannot update a node which has e.g. 400 characters set up with different
(generated) tags

I suggest to upper this limit to something a lot bigger - e.g. 2047 or so

thanks!

Comments

Christoph C. Cemper’s picture

anyone else got this?

benovic’s picture

yes, i have that problem, too.

on my site its also a little diseaster because i use community_tagging on the site. the module allows tags up to more than 255 chars, but then the node is no more editable.

is this fixed yet?

benovic’s picture

Priority: Critical » Minor

oh i just learned that this is very easily fixed by a mini module:
http://www.drupalcenter.de/node/7395#comment-27059

LAsan’s picture

Christoph C. Cemper: Still an issue?

slideaway’s picture

Since I don't speak german could someone spell out a little better what this mini-module fix entails? I see the bit of code, but where do I go about implementing it into my site? This is a somewhat critical issue on my site, as I definitely need the ability to tag more then the alloted limit.

slideaway’s picture

Anyone?

neclimdul’s picture

Make a small module(most sites have one of these to put small pieces of code in already) and do something along these lines:

function minimodule_form_alter($form_id, &$form) {
  if (isset($form['taxonomy']['tags'][VID])) {
    $form['taxonomy']['tags'][VID]['#maxlength'] = 500;
  }
}
tetty’s picture

I managed to solve this by changing the #maxlength value in the taxonomy module.
I then deleted my existing tags vocabulary and created another, which then had an increased maxlength

deadrich’s picture

Great tip, this solved the problem for me. Just a note, be sure to change VID to your taxonomy ID.

roychri’s picture

Here is something a bit more generic.
You do not have to modify the code (ie. VID), it work as-is.
It's more documented so hackers can dig in.
This is for Drupal 5 only

/**
 * Modify the create/edit node form so modify the behavior of the free
 * tagging vocabulary.
 */
function minimodule_form_alter($form_id, &$form) {
  // Only care when the form being shown is the form to create/edit a node.
  $editing_node = preg_match('/^(.+)_node_form$/', $form_id);

  // Only care when the form contains a free tag vocabulary.
  $contains_free_tags = isset($form['taxonomy']['tags']);

  if ($editing_node && $contains_free_tags) {

    foreach ($form['taxonomy']['tags'] as $vid => $info) {
      // Force the element to accept more characters than the default 255.
      $form['taxonomy']['tags'][$vid]['#maxlength'] = variable_get('max_freetag_vocabulary', 1024);

      // Complain if you provide too many characters.
      $form['taxonomy']['tags'][$vid]['#validate']['minimodule_validate_max_free_tags'] = array();
    }
  }
}

/**
 * Validate the number of characters in a free tagging vocabulary term.
 * Intended to be used in the form used to create/edit a node.
 * The goal is to prevent the field from silently cutting off the end
 * of your terms if you go over the limit.
 * This function is called by the form api when it is time to validate every elements.
 *
 */
function minimodule_validate_max_free_tags(&$element) {
  $threshold = $element['#maxlength'];
  $length = strlen($element['#value']);

  // I used the "greater than or equal" operator because the maxlength will
  // prevent the user from adding more characters.  If this value comes
  // from the web, this will generate an error if you reached exacly the max.
  // If you come from the drupal_execute(), this will allow you to specify
  // more characters.
  $exceeds_limit =  (bool)($length >= $threshold);

  if ($exceeds_limit) {
    $placeholders = array(
      '%threshold' => $threshold,
      '%field' => $element['#title'],
    );
    $message = t('You are not allowed to use %threshold characters or more in the field %field.', $placeholders);
    form_error($element,  $message);
  }
}

Installation Instructions as a new module

  1. Create a folder for your new module. Normally sites/all/modules/custom/minimodule/
  2. In that new folder create a minimodule.info (read documentation online to see how to do it)
  3. Create a minimodule.module and paste the code above
  4. Login as user 1 and go to admin/build/modules to enable this module

Installation Instructions in an existing module

  1. Paste this code into your existing module.
  2. Change the minimodule_ by whatever your module name is.
  3. If your module already had a form_alter hook, copy only the content of mine in yours.

Configuration

If you need more (or less) than 1024, simply change the value in your variable table like this:

REPLACE INTO variable VALUES ('max_freetag_vocabulary', 'i:2048;');
TRUNCATE TABLE cache;

Warning: The SQL above might only work in MySQL. I do not know if progresql support REPLACE.
Truncating the cache table allow your new value to take effect.

summit’s picture

Would be great to have this in D6 also!
Greetings, Martijn

bdsl’s picture

Version: 5.x-dev » 6.15

I've just had to do this in D6, and it just needs a slight change from the D5 version above:

<?php
/**
 * Extend the allowed length of lists of free terms.
 * This is code from drupal.org/node/157507 and should fix our issue 
 * #2165
 */

function taxonomy_length_extend_form_alter(&$form, &$form_state, $form_id) {
    if (isset($form['taxonomy']['tags'][7])) {  // where 7 is the ID of the taxonomy you want to adjust
          $form['taxonomy']['tags'][7]['#maxlength'] = 2000;  // where 7 is the ID of the taxonomy you want to adjust
                                                                               // and you want to allow 2000 chrs instead of the default 255
            }
}
hefox’s picture

Version: 6.15 » 5.x-dev

The limit isn't 255 in d6, it's like 1k. Something else was likely happening?

neclimdul’s picture

Status: Active » Closed (won't fix)

Confirmed, its 1024:

        $form['taxonomy']['tags'][$vocabulary->vid] = array('#type' => 'textfield',
          '#title' => $vocabulary->name,
          '#description' => $help,
          '#required' => $vocabulary->required,
          '#default_value' => $typed_string,
          '#autocomplete_path' => 'taxonomy/autocomplete/'. $vocabulary->vid,
          '#weight' => $vocabulary->weight,
          '#maxlength' => 1024,
        );

Its possible someone is trying to put more then 1k characters of tags but thats a lot of tags...

Going to go out on a limb and mark this WF. We don't support 5.x, there's a posted workaround, and it doesn't really exist in > 6.x.