summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2005-11-21 16:21:51 +0000
committerDries Buytaert <dries@buytaert.net>2005-11-21 16:21:51 +0000
commit463ffe24ece31fd094ca30ce8b8b485ee32161cf (patch)
treeb30abca4eaf8112be115ad9554bb9f1ce0467cbd
parent17205b6e6201af0e4dea338009be794fddbc1712 (diff)
downloadbrdo-463ffe24ece31fd094ca30ce8b8b485ee32161cf.tar.gz
brdo-463ffe24ece31fd094ca30ce8b8b485ee32161cf.tar.bz2
- Patch #35724 by asimmonds: fixed handling of empty form fields.
-rw-r--r--includes/form.inc6
1 files changed, 4 insertions, 2 deletions
diff --git a/includes/form.inc b/includes/form.inc
index e5bfd61d9..e7fbb4751 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -140,8 +140,10 @@ function _form_validate($elements) {
/* Validate the current input */
if (!$elements['#validated'] && $elements['#input']) {
- if ($elements['#required'] && !isset($elements['#value'])) {
- form_error($elements, t('%name field is required', array('%name' => $elements['#title'])));
+ // An empty checkbox returns 0, an empty textfield returns '' so we use empty().
+ // Unfortunately, empty('0') returns TRUE so we need a special check for the '0' string.
+ if ($elements['#required'] && empty($elements['#value']) && $elements['#value'] !== '0') {
+ form_error($elements, t('%name field is required', array('%name' => $elements['#title'])));
}
if ($elements['#valid']) {
if (is_array($elements['#valid'])) {