Form API Validation: Add New Filter for ucfirst 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 `ucfirst` function to input values. This can lead to inconsistencies in user input where the first character of a string is not capitalized, resulting in unformatted or less professional data being stored.
Adding a filter for ucfirst would allow developers to automatically capitalize the first letter of input values, ensuring cleaner and more consistent data formatting.

Proposed resolution

Introduce a new filter option for Form API Validation to apply the `ucfirst` function to input values. This filter will:
Automatically capitalize the first letter of 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' => [
    'ucfirst' => [],
  ],
];
✨ 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