Skip to content
Snippets Groups Projects
Commit 06bb3d2e authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

#117748 by quicksketch: short fix to trim() required fields for validation, with documentation

parent a387aaee
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -664,10 +664,10 @@ function _form_validate($elements, &$form_state, $form_id = NULL) { ...@@ -664,10 +664,10 @@ function _form_validate($elements, &$form_state, $form_id = NULL) {
// Validate the current input. // Validate the current input.
if (!isset($elements['#validated']) || !$elements['#validated']) { if (!isset($elements['#validated']) || !$elements['#validated']) {
if (isset($elements['#needs_validation'])) { if (isset($elements['#needs_validation'])) {
// An empty textfield returns '' so we use empty(). An empty checkbox // We only check for trimmed string length being zero. 0 might be
// and a textfield could return '0' and empty('0') returns TRUE so we // a possible value with some field types, such as radio buttons, so
// need a special check for the '0' string. // empty() is not usable here.
if ($elements['#required'] && empty($elements['#value']) && $elements['#value'] !== '0') { if ($elements['#required'] && strlen(trim($elements['#value'])) == 0) {
form_error($elements, $t('!name field is required.', array('!name' => $elements['#title']))); form_error($elements, $t('!name field is required.', array('!name' => $elements['#title'])));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment