Commit eb412f7c authored by Dries's avatar Dries

- Patch #39179 by chx: improved validation of forms.

parent 0212f66f
......@@ -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);
......
......@@ -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.
*/
......
......@@ -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.
*/
......
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