form_set_error
- Versions
- 4.6
form_set_error($name, $message)- 4.7 – 5
form_set_error($name = NULL, $message = '')- 6
form_set_error($name = NULL, $message = '', $reset = FALSE)
File an error against a form element.
Parameters
$name The name of the form element. If the #parents property of your form element is array('foo', 'bar', 'baz') then you may set an error on 'foo' or 'foo][bar][baz'. Setting an error on 'foo' sets an error for every element where the #parents array starts with 'foo'.
$message The error message to present to the user.
$reset Reset the form errors static cache.
Return value
Never use the return value of this function, use form_get_errors and form_get_error instead.
Related topics
Code
includes/form.inc, line 797
<?php
function form_set_error($name = NULL, $message = '', $reset = FALSE) {
static $form = array();
if ($reset) {
$form = array();
}
if (isset($name) && !isset($form[$name])) {
$form[$name] = $message;
if ($message) {
drupal_set_message($message, 'error');
}
}
return $form;
}
?>Login or register to post comments 