summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGábor Hojtsy2008-02-08 18:05:01 (GMT)
committerGábor Hojtsy2008-02-08 18:05:01 (GMT)
commitceef51d424dfaf422c041fea4cada25d490318bc (patch)
tree6667a149cfd999374ab944e83de6dd3dd402c144
parentc7f6540adcf68b683b7245babdbc937e75add681 (diff)
#117748 by webchick, Pancho, Rob Loach, pwolanin: required field values were not properly trim()ed on validation
-rw-r--r--includes/form.inc9
1 files changed, 5 insertions, 4 deletions
diff --git a/includes/form.inc b/includes/form.inc
index 93b455a..c327eca 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -664,10 +664,11 @@ 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') {
+ // Make sure a value is passed when the field is required.
+ // A simple call to empty() will not cut it here as some fields, like
+ // checkboxes, can return a valid value of '0'. Instead, check the
+ // length if it's a string, and the item count if it's an array.
+ if ($elements['#required'] && (!count($elements['#value']) || (is_string($elements['#value']) && strlen(trim($elements['#value'])) == 0))) {
form_error($elements, $t('!name field is required.', array('!name' => $elements['#title'])));
}