Matt Glaman: Trimming whitespace from Drupal form submissions using an HTTP middleware

Sponsored:

If someone googles you right now and you don’t come up? You might as well not exist. Every client, opportunity and connection is passing you by.

You don’t need to know code. RoseHosting lets you launch something you’re proud of this afternoon.

Stop hiding. Build yours today.

Author:
Source

Leading and trailing whitespaces. The bane of normalized data everywhere. It seems like a constant task that needs to be performed on incoming user data. When working with Laravel, I use the TrimStrings middleware. Calls PHP’s built-in trim function on all string values for the request query and input values – including JSON! While working on my project WhiskeyDex, I noticed how mobile device keyboards always add trailing whitespace when using the autocomplete functionality. This, in turn, meant user-created data will end up with trailing whitespaces. I started to just quick-fix in the single instance and realized it should be solved once and for all.

Read more