function form_basic_validate
Search API
7.x render.inc | form_basic_validate($form, $form_state) |
6.x render.inc | form_basic_validate($form, |
4.x forms.inc | form_basic_validate($form, $form_submitted) |
5.x render.inc | form_basic_validate($form, $form_submitted) |
This is a very basic validator for form API submission. All I really care about is making sure required fields have a value in them. If they do not, we will file a form_error.
1 call to form_basic_validate()
- system_handle_form_submit in modules/
system/ system.module - Intercepts form submissions from forms built with the form API.
File
- includes/
render.inc, line 416
Code
function form_basic_validate($form, $form_state) {
foreach ($form as $name => $element) {
if (is_array($element) && @$element ["required"]) {
// Okay, this is a required field. So, check that it has a non-blank value
// in form_submitted.
if ($form_state ["values"][$name] == "") {
// It's blank! ERROR!
$label = $element ["label"];
if ($label == "") {
$label = $name;
}
form_error($name, t("You must enter a value for <b>%element_label</b>.", array("%element_label" => $label)));
}
} // if is_array element and required
if (is_array($element) && isset($element ['type']) && $element ['type'] == 'value') {
$should_be_value = @trim($form [$name]['value']);
$found_value = @trim($form_state ['values'][$name]);
if ($should_be_value !== $found_value) {
form_error('', t("Invalid value found in form, possible hacking attempt or bug. This incident has been logged.", array("%element_label" => $label)));
watchdog('system', "Invalid value found in form, possible hacking attempt or bug. Should be value: '$should_be_value', Found value: '$found_value' ", array(), WATCHDOG_ERROR);
}
} // if element is of type "value"
}
}