The problem:

I set up Tokens to create ALT text for my images however the Tokens I chose to use created long ALT texts. I don't have a problem with that, but ImageField does. I kept getting a warning message stating that the ALT text must be less than 80 chars and all the uploads would fail.

The solution I found was:

Create a new setting entry in the variable DB table named "imagefield_alt_length" and set it to a larger number (I set it to 150).

If that doesn't work, then edit the imagefield_widget.inc file in the imagefield module directory. Look for line 242 which reads:

'#maxlength' => variable_get('imagefield_alt_length', 80), //

Change the value of 80 to a higher number.

I know that search engines only read the first 80 chars of of some webpage elements. This probably includes image ALT text. I don't care about this, I just needed it to stop throwing errors because the dynamic alt tags that Tokens was generating for me was larger than 80 chars.

I hope this helps someone else.

Please post if there's a better way to fix this.

Comments

quicksketch’s picture

Category: feature » support
Status: Needs review » Active

This is not "needs review" because there's no patch attached. ImageField will stay with the limit at 80 characters because that's the limit recommended on ALT tags by usability efforts such as 508 compliance (in the US) and multiple international standards. You can change this value on your personal site by setting the variable "imagefield_alt_length" to a greater value, but I would not recommend it.

You can set this value simply by editing your database (the row is in the "variable" table), by using the variable editor in the devel.module, or by setting the value in settings.php (per the documentation included near the bottom of the file).

Coleslaw’s picture

Thanks for your response.

Perhaps there needs to be a soft warning stating the generated ALT tag is longer than the recommended 80 chars and let the user continue saving the node. The way it is now, all image uploads come to a grinding halt until a solution can be found.

Alternately, if you are really anal about standards, you could have it crop the string to 80 chars. Either way, you can't expect dynamic ALT tags to all be under 80 chars - their length is going to bounce around depending on the format chosen to generate them.

The imagefield_alt_length variable isn't added to the variable table by ImageField (at least it wasn't for me and I don't see it in the install code), so unless someone goes code diving, they won't know that all that is need is to create and set a new variable named imagefield_alt_length to get around the 80 char limit. The variable table was the first place I looked for a setting but I found none there. Thus the reason for my post. I just want to save someone else the time searching for a solution.

niklp’s picture

I'm having issues with this as well, and I have to concur that the potential problem with tokens is at least an annoyance.

Simply warning that the max is 80 for search engines but allowing more seems sane enough to me. Perhaps we could put a jquery character counting widget on the field? (overkill perhaps).

Either way there needs to be some sort of improvement even if it's only a text-based warning.

quicksketch’s picture

Hmm, all of these suggestions are based on the assumption that you're going to enter an ALT text longer than 80 characters anyway. I'd still suggest setting the variable higher than 80 characters in your settings.php.

$conf['imagefield_alt_length'] = 500;

Getting the 80 character error normally isn't even possible for a user entering an ALT string, because the textfield limits them at 80 characters through the "maxlength" property on the field.

Coleslaw’s picture

Ya, manually entering ALT tags wouldn't be a problem. I'm using Tokens to dynamically create the ALT tags and the modules are banging heads on this ALT length issue.

Changing "imagefield_alt_length" is definately the solution tho, I agree. Hopefully people will find this thread and save a few hours trying to figure it out.

quicksketch’s picture

Status: Active » Closed (fixed)

Closing after lack of activity.

brian_c’s picture

Version: 6.x-3.0-rc1 » 6.x-3.7

Just ran into this issue with automatically generated alt text.

The problem occurs not because people try to exceed 80 characters manually, but when they later try to edit a node that was created automatically, and get a validation error that isn't their fault, has nothing to do with what they're trying to edit, and is a pain to fix. Result: The user gives up on the edit.

Certainly one solution is to increase the max length, but what if we WANT to enforce the 80 char limit?

Perhaps we should consider that, in addition to a user input validation issue, limiting the length of ALT text sent to the browser is ALSO a rendering issue, which may (as we see with the people in this thread) have nothing to do with form-based user input.

With that in mind, what about introducing a new variable, perhaps called "imagefield_alt_display_length", which also defaults to 80. ImageField could use this value with a simple truncate_utf8() call when the alt text is rendered, and themers would have access to the full raw value if they wish to override the default implementation.

Then people who run into this problem can simply up the "input" value (ie, the original "imagefield_alt_length" variable) so that the node form reflects the reality of what is getting inserted via automatically generated text, while the new "display" value continues to provide the nice standards-compliant 80 char display length.

Whatdya think?

codevoice’s picture

+1, in my case I am using tokens and ending up with alt text longer than 80 characters. Instead of increasing the limit, I would simply like to take the first 80 characters rendered and dump the rest... no error needed (or a soft warning if anything).

This idea was floated above, has anyone had any luck with this approach?