Trim

Component ID

2437819

Component name

Trim

Component type

module

Maintenance status

Development status

Component security advisory coverage

covered

Downloads

1157

Component created

Component changed

Component body

Trim strips all leading and trailing whitespace from all fields in all form submissions.

The module trims prior to validation, so for instance if you have an integer field and a person entering data fat-fingers a space after a number, he gets a successfully saved node rather than an error message about invalid input.

Because blank spaces are likely trimmed or invisible in rendered HTML, you are most likely to see the corrective effects of this module in alphabetical lists such as from Views. So if the proprietor of We Didn't Think Alphabetical Order Mattered On The Internet tries to jump ahead of Aardvark Agency in your directory, she'll be disappointed.

Trimming all form entries everywhere behavior may be a tad aggressive (for instance, if you have an options selection where you've made a key a single ' ' for some reason, or want to allow leading or trailing spaces on a field), but note that Drupal already trims whitespace from passwords without warning, so Trim just extends this behavior to all fields.

Trim module is based on (read: taken in its entirety) from exratione's blog post, Drupal: Trim All Form Fields Everywhere. Exratione has blessed contributing the code here and therefore deserves all credit if this module saves your sanity by sanitizing all stray spaces in your users' input. If it blows up your site file a ticket for me.

Note again that it trims values prior to saving, so it is in fact changing what people enter. This seems a reasonable exception to Drupal's rule of not messing with user input and doing all adjustments on output.

Again, credit to Exratione.

Image credit: WikiMedia Commons