Problem/Motivation
Currently, the Form API Validation module does not provide a built-in filter to automatically apply ltrim to input values. This can lead to issues where leading whitespace in user input is not removed, resulting in unexpected validation failures or inconsistent data storage.
Adding a filter for ltrim would allow developers to automatically trim leading whitespace from input values, ensuring cleaner and more predictable user input.
Proposed resolution
Introduce a new filter option for Form API Validation to apply the ltrim function to input values. This filter will:
Automatically remove leading whitespace 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' => [
'ltrim' => [],
],
];
Remaining tasks
Implement the ltrim filter functionality in the Form API Validation module.
Add test coverage to validate the behavior of the ltrim filter.
Update the module documentation to include usage details for the ltrim 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 (ltrim) in the #filters array for Form API fields.
Ensure the ltrim 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.