function _form_validate in Drupal 4
Same name and namespace in other branches
- 5 includes/form.inc \_form_validate()
- 6 includes/form.inc \_form_validate()
- 7 includes/form.inc \_form_validate()
Related topics
1 call to _form_validate()
- drupal_validate_form in includes/form.inc
File
- includes/form.inc, line 219
Code
function _form_validate($elements, $form_id = NULL) {
foreach (element_children($elements) as $key) {
if (isset($elements[$key]) && $elements[$key]) {
_form_validate($elements[$key]);
}
}
if (!$elements['#validated']) {
if (isset($elements['#needs_validation'])) {
if ($elements['#required'] && empty($elements['#value']) && $elements['#value'] !== '0') {
form_error($elements, t('%name field is required.', array(
'%name' => $elements['#title'],
)));
}
if (isset($elements['#options']) && isset($elements['#value']) && !isset($elements['#DANGEROUS_SKIP_CHECK'])) {
if ($elements['#type'] == 'select') {
$options = form_options_flatten($elements['#options']);
}
else {
$options = $elements['#options'];
}
if (is_array($elements['#value'])) {
$value = $elements['#type'] == 'checkboxes' ? array_keys(array_filter($elements['#value'])) : $elements['#value'];
foreach ($value as $v) {
if (!isset($options[$v])) {
form_error($elements, 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($elements['#title']) ? $elements['#parents'][0] : $elements['#title']),
)), WATCHDOG_ERROR);
}
}
}
elseif (!isset($options[$elements['#value']])) {
form_error($elements, 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', $elements['#value']),
'%name' => theme('placeholder', empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']),
)), WATCHDOG_ERROR);
}
}
}
if (isset($elements['#validate'])) {
foreach ($elements['#validate'] as $function => $args) {
$args = array_merge(array(
$elements,
), $args);
if (isset($form_id)) {
$args = array_merge(array(
$form_id,
$GLOBALS['form_values'],
), $args);
}
if (function_exists($function)) {
call_user_func_array($function, $args);
}
}
}
$elements['#validated'] = TRUE;
}
}