Drupal is a registered trademark of Dries Buytaert
cms 2.1.2 Update released for Drupal core (2.1.2)! drupal 11.1.10 Update released for Drupal core (11.1.10)! drupal 10.5.10 Update released for Drupal core (10.5.10)! drupal 10.4.10 Update released for Drupal core (10.4.10)! drupal 11.2.12 Update released for Drupal core (11.2.12)! drupal 11.3.10 Update released for Drupal core (11.3.10)! drupal 10.6.9 Update released for Drupal core (10.6.9)! drupal 10.6.8 Update released for Drupal core (10.6.8)! drupal 11.3.9 Update released for Drupal core (11.3.9)! drupal 11.3.8 Update released for Drupal core (11.3.8)! drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! linkit 7.0.15 Minor update available for module linkit (7.0.15). views_data_export 8.x-1.10 Minor update available for module views_data_export (8.x-1.10).

trim

Security covered
View on drupal.org

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

This works for content titles, plain text fields, and usernames, for example.

The module trims prior to form 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. (Note: HTML validation triggers an error for blank spaces in input fields of type email or number before this module can act.)

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.

Note that Drupal already trims whitespace from passwords without warning. Drupal's "Autocomplete (Tags style)" form field widget also trims all surrounding spaces from terms. Trim extends this behavior to all text fields on all content entities. (In the Drupal context, users and taxonomy terms are 'content'.)

Trimming all form entries everywhere was deemed too 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), so we do not trim input on configuration forms.

Trim module is based on exratione's blog post, Drupal: Trim All Form Fields Everywhere. Exratione deserves all credit if this module saves your sanity by sanitizing all stray spaces in your users' input. If it blows up your site, though, file a ticket here.

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. If you think there should be an option to warn people when their input is trimmed, please contribute to #3388667: Alert people when their text is trimmed.

Caveats

Image credit: WikiMedia Commons

And again, credit to Exratione.

Activity

Total releases
1
First release
May 2026
Latest release
23 hours ago
Release cadence
Stability
0% stable

Releases

Version Type Release date
3.0.x-dev Dev May 23, 2026