#52484 by chx: filter_form needs validation
parent
d797819821
commit
4b663a62af
|
@ -170,7 +170,8 @@ function drupal_submit_form($form_id, $form, $callback = NULL) {
|
|||
|
||||
function _form_validate($elements, $form_id = NULL) {
|
||||
/* Validate the current input */
|
||||
if (!$elements['#validated'] && ($elements['#input'] || isset($form_id))) {
|
||||
if (!$elements['#validated']) {
|
||||
if ($elements['#input'] || isset($form_id)) {
|
||||
// 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.
|
||||
|
@ -200,6 +201,7 @@ function _form_validate($elements, $form_id = NULL) {
|
|||
watchdog('form', t('Illegal choice %choice in %name element.', array('%choice' => theme_placeholder(check_plain($v)), '%name' => theme('placeholder', empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'])), WATCHDOG_ERROR));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// User-applied checks.
|
||||
if (isset($elements['#validate'])) {
|
||||
|
|
|
@ -802,6 +802,7 @@ function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents =
|
|||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#weight' => $weight,
|
||||
'#validate' => array('filter_form_validate' => array()),
|
||||
);
|
||||
// Multiple formats available: display radio buttons with tips.
|
||||
foreach ($formats as $format) {
|
||||
|
@ -829,6 +830,16 @@ function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents =
|
|||
return $form;
|
||||
}
|
||||
|
||||
function filter_form_validate($form) {
|
||||
foreach (element_children($form) as $key) {
|
||||
if ($form[$key]['#value'] == $form[$key]['#return_value']) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
form_error($form, t('An illegal choice has been detected. Please contact the site administrator.'));
|
||||
watchdog('form', t('Illegal choice %choice in %name element.', array('%choice' => theme('placeholder', check_plain($v)), '%name' => theme_placeholder(empty($form['#title']) ? $form['#parents'][0] : $form['#title'])), WATCHDOG_ERROR));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the user is allowed to access this format.
|
||||
*/
|
||||
|
|
|
@ -802,6 +802,7 @@ function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents =
|
|||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#weight' => $weight,
|
||||
'#validate' => array('filter_form_validate' => array()),
|
||||
);
|
||||
// Multiple formats available: display radio buttons with tips.
|
||||
foreach ($formats as $format) {
|
||||
|
@ -829,6 +830,16 @@ function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents =
|
|||
return $form;
|
||||
}
|
||||
|
||||
function filter_form_validate($form) {
|
||||
foreach (element_children($form) as $key) {
|
||||
if ($form[$key]['#value'] == $form[$key]['#return_value']) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
form_error($form, t('An illegal choice has been detected. Please contact the site administrator.'));
|
||||
watchdog('form', t('Illegal choice %choice in %name element.', array('%choice' => theme('placeholder', check_plain($v)), '%name' => theme_placeholder(empty($form['#title']) ? $form['#parents'][0] : $form['#title'])), WATCHDOG_ERROR));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the user is allowed to access this format.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue