Form API Validation: Add New Filter for rtrim 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 rtrim to input values. This can lead to issues where trailing space in user input is not removed, resulting in unexpected validation failures or inconsistent data storage.

Adding a filter for rtrim would allow developers to automatically trim trailing space from input values, ensuring cleaner and more predictable user input.

Proposed resolution

Introduce a new filter option for Form API Validation to apply the rtrim function to input values. This filter will:

Automatically remove trailing space from user input when applied.
Be configurable at the form element level, similar to existing filters like trim.
Example usage in a form definition:

php
Copy code
$form['example_textfield'] = [
'#type' => 'textfield',
'#title' => t('Example Field'),
'#filters' => [
'rtrim' => [],
],
];

Remaining tasks

Implement the rtrim filter functionality in the Form API Validation module.
Add test coverage to validate the behavior of the rtrim filter.
Update the module documentation to include usage details for the rtrim filter.

User interface changes

No user interface changes are required. This enhancement is configuration-driven and does not directly affect the module's UI.

API changes

Add a new filter key (rtrim) in the #filters array for Form API fields.
Ensure the rtrim filter is applied during form input processing.

Data model changes

No changes to the data model are required, as this enhancement operates on input processing only.

✨ 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