Form API Validation: Add New Filter for ucwords Input Values

Created on 24 January 2025, 4 days ago

Problem/Motivation

Currently, the Form API Validation module does not provide a built-in filter to automatically apply the `ucwords` function to input values. This can lead to inconsistencies in user input where the first letter of each word in a string is not capitalized, resulting in unformatted or less professional data being stored.
Adding a filter for ucwords would allow developers to automatically capitalize the first letter of each word in input values, ensuring cleaner and more consistent data formatting.

Proposed resolution

Introduce a new filter option for Form API Validation to apply the `ucwords` function to input values. This filter will:
Automatically capitalize the first letter of each word in user input when applied.
Be configurable at the form element level, similar to existing filters like trim.
Example usage in a form definition:

$form['example_textfield'] = [
  '#type' => 'textfield',
  '#title' => t('Example Field'),
  '#filters' => [
    'ucwords' => [],
  ],
];
✨ Feature request
Status

Active

Version

3.0

Component

Code

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024