Skip to main content
drupalreleases
Release: Cms 2.2.3 — Update released for Drupal core (2.2.3)! Release: Easy Breadcrumb 2.0.11 — Minor update available for module easy_breadcrumb (2.0.11). Release: Bootstrap 8.x-3.42 — Minor update available for theme bootstrap (8.x-3.42). Release: Editoria11y Accessibility Checker 3.0.10 — Minor update available for module editoria11y (3.0.10). Release: Editoria11y Accessibility Checker 2.2.24 — Minor update available for module editoria11y (2.2.24). Release: Leaflet 10.4.13 — Minor update available for module leaflet (10.4.13). Release: Flag 5.1.1 — Minor update available for module flag (5.1.1). Release: MCP Sentinel 2.33.0 — Minor update available for module mcp_sentinel (2.33.0). Module Revived: Bootstrap 8.x-3.41 — Theme bootstrap updated after 6 months of inactivity (8.x-3.41). Security Coverage: Component Library — Module component_library now has official Drupal security advisory coverage.

Trim

1,878 sites Security covered Drupal 8–11
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.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
4
Tracked since
Sep 2023
Latest release
4 months ago
Releases (12 mo)
1
Maintenance
Active

Release Timeline

Releases

Version Type Core Release date
3.0.x-dev Dev 11 May 23, 2026
2.0.1 Stable 8–11 Oct 29, 2024
2.0.0 Stable 8–10 Sep 20, 2023
2.0.x-dev Dev 8–11 Sep 20, 2023