Commit ceef51d4 authored by Gábor Hojtsy's avatar Gábor Hojtsy

#117748 by webchick, Pancho, Rob Loach, pwolanin: required field values were...

#117748 by webchick, Pancho, Rob Loach, pwolanin: required field values were not properly trim()ed on validation
parent c7f6540a
...@@ -664,10 +664,11 @@ function _form_validate($elements, &$form_state, $form_id = NULL) { ...@@ -664,10 +664,11 @@ 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 // Make sure a value is passed when the field is required.
// and a textfield could return '0' and empty('0') returns TRUE so we // A simple call to empty() will not cut it here as some fields, like
// need a special check for the '0' string. // checkboxes, can return a valid value of '0'. Instead, check the
if ($elements['#required'] && empty($elements['#value']) && $elements['#value'] !== '0') { // 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']))); form_error($elements, $t('!name field is required.', array('!name' => $elements['#title'])));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment