You are here

function form_set_error in Drupal 6

Same name and namespace in other branches
  1. 4 includes/form.inc \form_set_error()
  2. 5 includes/form.inc \form_set_error()
  3. 7 includes/form.inc \form_set_error()

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

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

... See full list

File

includes/form.inc, line 855

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