- Form handlers and API code manually calls
trim()on values too many times.
- It's unclear who is responsible for trimming text values / user input.
- The lack of custom
trim()calls can trigger error messages that are hard to recognize and resolve by a user, in case a submitted form value contains leading or trailing white-space (which is not visible/apparent).
- Introduce a generic
#trimproperty for all form elements that accept
#trimdefault to TRUE for all form element types that accept text as user input.
form_handle_input_element(). If the resulting #value is an empty string, trigger the regular processing flow that would be triggered for no user input - including #required validation.
- Allow code that does not want this behavior to opt-out by setting #trim to FALSE. (There's no use-case for that in core, but still...)
- Remove all manual calls into
trim()from API code. Whoever is calling into APIs is expected to provide proper (trimmed) values.
If the user registers and by mistake includes and extra space before or after their email address, the system will reject the email address with an error message that is difficult to understand (as there is nothing obvious wrong with the email address). I have seen this several times when I paste my email address into the email address box and mistakenly include a trailing space. I just tried it on the Drupal.org site and got the error:
"The e-mail address email@example.com is not valid."
My guess is that this problem might affect 2-3% of all users who ever try to set up Drupal accounts and leave them a bit frustrated.
It would be very easy to have the form on the page user/register trim the spaces off of the email address, to solve this problem.
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch drupal8.form-trim.73.patch. Unable to apply patch. See the log in the details link for more information. View
FAILED: [[SimpleTest]]: [MySQL] 49,706 pass(es), 4 fail(s), and 0 exception(s). View
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch drupal8.form-trim.65.patch. Unable to apply patch. See the log in the details link for more information. View
FAILED: [[SimpleTest]]: [MySQL] 48,722 pass(es), 2 fail(s), and 0 exception(s). View
FAILED: [[SimpleTest]]: [MySQL] 48,629 pass(es), 7 fail(s), and 0 exception(s). View