From 06bb3d2e095fa58c69a5941e5e9475293732ae4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Hojtsy?= <gabor@hojtsy.hu> Date: Mon, 4 Feb 2008 10:23:32 +0000 Subject: [PATCH] #117748 by quicksketch: short fix to trim() required fields for validation, with documentation --- includes/form.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/form.inc b/includes/form.inc index 1ba20a14d540..62579848b820 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -664,10 +664,10 @@ function _form_validate($elements, &$form_state, $form_id = NULL) { // Validate the current input. if (!isset($elements['#validated']) || !$elements['#validated']) { if (isset($elements['#needs_validation'])) { - // An empty textfield returns '' so we use empty(). An empty checkbox - // and a textfield could return '0' and empty('0') returns TRUE so we - // need a special check for the '0' string. - if ($elements['#required'] && empty($elements['#value']) && $elements['#value'] !== '0') { + // We only check for trimmed string length being zero. 0 might be + // a possible value with some field types, such as radio buttons, so + // empty() is not usable here. + if ($elements['#required'] && strlen(trim($elements['#value'])) == 0) { form_error($elements, $t('!name field is required.', array('!name' => $elements['#title']))); } -- GitLab