It's strange that this isn't even a standard feature in Drupal, because I've had to implement it in projects more times than I can count:
You're creating a new content type, and based on the design, you really want to limit a field or two to a certain number of characters. You can, of course, trim the output on the display or via views, etc, but sometimes you don't want to just trim or cut off the field - you want the author to ensure it makes sense within that character limit by enforcing it on the input end rather than just cutting it off during display!
It is exceedingly easy to use!
Here is what a standard node edit form looks like before I set up the maxlength module (this example uses a 'Bio' content type):
As you can see, I have a very long body field.
To start limiting my field characters, I need to setup the maxlength module the following way:
- Download and install the module normally: https://drupal.org/project/maxlength
- There is no module-specific configuration
- Go to your content type's 'Manage fields' screen and hit 'Edit' next to the field you want to character-limit.
- Maxlength JS - enter in the maximum character length you want enforced for the field
- Force text truncate - check this box if you want the user's pasted or entered text in the editing interface itself to be truncated the minute they hit the character limit. Otherwise, their text can grow past the character limit, though they won't be able to 'save' their entry and their character count will show them how many characters they are over
- Truncate html - if the field is an HTML field, rather than plain text, this option, when checked, ensures that the character count does not include html tags (and thus also prevents faulty html)
- Count down message - I usually leave the default here, but you can change the exact message that is shown under the field, letting the user know the character limit and how many characters they have left (they are negatives when they are over).
- Here is the same editing screen after I set up the maximum character count of 550 on the Body field of my Bio content type (just as above):
Wow - my field is waaaaay too long (5 whole paragraphs).
As you can see there is minimal setup and the field configuration options are few and intuitive. Hope this was helpful and that you'll have no trouble using this module in your future projects.
Let me know if you have any questions or comments below.