summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2005-12-19 14:30:53 +0000
committerDries Buytaert <dries@buytaert.net>2005-12-19 14:30:53 +0000
commiteb412f7c7e15a8bd4e572d28e12ecaab59a7c0f7 (patch)
tree1dc312c8a2cc1831c8ba55750b7c57ddc1d7820b
parent0212f66ff1682ab699830d7571a5ff5ee85aa725 (diff)
downloadbrdo-eb412f7c7e15a8bd4e572d28e12ecaab59a7c0f7.tar.gz
brdo-eb412f7c7e15a8bd4e572d28e12ecaab59a7c0f7.tar.bz2
- Patch #39179 by chx: improved validation of forms.
-rw-r--r--includes/form.inc18
-rw-r--r--modules/filter.module13
-rw-r--r--modules/filter/filter.module13
3 files changed, 18 insertions, 26 deletions
diff --git a/includes/form.inc b/includes/form.inc
index a57ffa2b2..300b78267 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -145,6 +145,24 @@ function _form_validate($elements, $form_id = NULL) {
if ($elements['#required'] && empty($elements['#value']) && $elements['#value'] !== '0') {
form_error($elements, t('%name field is required', array('%name' => $elements['#title'])));
}
+
+ // Add legal choice check if element has #options.
+ if (isset($elements['#options']) && isset($elements['#value'])) {
+ $message = t('Illegal choice in %title.', array('%title' => theme('placeholder', $elements['#title'])));
+ if (is_array($elements['#value'])) {
+ $value = $elements['#type'] == 'checkboxes' ? array_keys(array_filter($elements['#value'])) : $elements['#value'];
+ foreach ($value as $v) {
+ if (!isset($elements['#options'][$v])) {
+ form_error($elements, $message);
+ }
+ }
+ }
+ elseif (!isset($elements['#options'][$elements['#value']])) {
+ form_error($elements, $message);
+ }
+ }
+
+ // User-applied checks.
if (isset($elements['#validate'])) {
foreach ($elements['#validate'] as $function => $args) {
$args = array_merge(array($elements), $args);
diff --git a/modules/filter.module b/modules/filter.module
index 88cb98801..b81039879 100644
--- a/modules/filter.module
+++ b/modules/filter.module
@@ -775,7 +775,6 @@ function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = 0, $parents = arr
'#return_value' => $format->format,
'#parents' => $parents,
'#description' => theme('filter_tips', _filter_tips($format->format, false)),
- '#validate' => array('filter_form_validate' => array())
);
}
}
@@ -793,18 +792,6 @@ function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = 0, $parents = arr
return $form;
}
-function filter_form_validate($element) {
- static $validated;
- if ($validated) {
- return;
- }
- $validated = 1;
- $formats = filter_formats();
- if (!isset($formats[$element['#value']])) {
- form_set_error($element['#parents'][0], t('The supplied input format is invalid.'));
- }
-}
-
/**
* Returns true if the user is allowed to access this format.
*/
diff --git a/modules/filter/filter.module b/modules/filter/filter.module
index 88cb98801..b81039879 100644
--- a/modules/filter/filter.module
+++ b/modules/filter/filter.module
@@ -775,7 +775,6 @@ function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = 0, $parents = arr
'#return_value' => $format->format,
'#parents' => $parents,
'#description' => theme('filter_tips', _filter_tips($format->format, false)),
- '#validate' => array('filter_form_validate' => array())
);
}
}
@@ -793,18 +792,6 @@ function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = 0, $parents = arr
return $form;
}
-function filter_form_validate($element) {
- static $validated;
- if ($validated) {
- return;
- }
- $validated = 1;
- $formats = filter_formats();
- if (!isset($formats[$element['#value']])) {
- form_set_error($element['#parents'][0], t('The supplied input format is invalid.'));
- }
-}
-
/**
* Returns true if the user is allowed to access this format.
*/