Drupal is a registered trademark of Dries Buytaert
Release: Leaflet 10.4.11 Minor update available for module leaflet (10.4.11). Release: Session Inspector 1.0.8 Minor update available for module session_inspector (1.0.8). Release: Migrate QA 2.0.4 Minor update available for module migrate_qa (2.0.4). Release: CKEditor Description List 3.0.0 Major update available for module ckeditor_descriptionlist (3.0.0). Release: FlowDrop 2.4.0 Minor update available for module flowdrop (2.4.0). Release: JWT Token Refresh 1.0.4 Minor update available for module jwt_token_refresh (1.0.4). Release: ConReg 1.0.0-beta1 First beta version released for module conreg (1.0.0-beta1). Release: AI Image Studio 1.0.0-beta8 New beta version released for module ai_image_studio (1.0.0-beta8). Usage Milestone: Statistics Counter Module statistics_counter crossed 1,000 active installs. Module Revived: Decoupled Router 2.0.7 Module decoupled_router updated after 11 months of inactivity (2.0.7).

Trim

1,862 sites Security covered
View on drupal.org

This module automatically removes leading and trailing whitespace from all text fields in content and user forms. It ensures cleaner data by trimming spaces before saving, preventing issues like incorrect sorting in lists or validation errors. This functionality is applied to content titles, plain text fields, usernames, and other text-based inputs, but intentionally excludes configuration forms to avoid unintended data modification.

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

Tracked releases
1
Tracked since
May 2026
Latest release
3 months ago
Releases (12 mo)
1 ▲ from 0
Maintenance
Active

Releases

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