function form_set_error

7.x form.inc form_set_error($name = NULL, $message = '', $limit_validation_errors = NULL)
6.x form.inc 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

66 calls to form_set_error()
aggregator_form_category_validate in drupal-6.x/modules/aggregator/aggregator.admin.inc
Validate aggregator_form_feed form submissions.
aggregator_form_feed_validate in drupal-6.x/modules/aggregator/aggregator.admin.inc
Validate aggregator_form_feed form submissions.
block_add_block_form_validate in drupal-6.x/modules/block/block.admin.inc
block_admin_configure_validate in drupal-6.x/modules/block/block.admin.inc
book_admin_edit_validate in drupal-6.x/modules/book/book.admin.inc
Check that the book has not been changed while using the form.

... See full list

File

drupal-6.x/includes/form.inc, line 816

Code

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;
}