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)
7
form_set_error($name = NULL, $message = '')

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

▾ 20 functions call form_set_error()

comment_form_validate in modules/comment/comment.module
Validate comment form submissions.
drupal_validate_form in includes/form.inc
Validates user-submitted form data from the $form_state using the validate functions defined in a structured form array.
file_save_upload in includes/file.inc
Saves a file upload to a new location.
form_error in includes/form.inc
Flag an element as having an error.
form_get_error in includes/form.inc
Return the error message filed against the form with the specified name.
form_get_errors in includes/form.inc
Return an associative array of all errors.
hook_node_validate in modules/node/node.api.php
The user has finished editing the node and is previewing or submitting it.
hook_prepare in modules/node/node.api.php
This is a hook used by node modules. It is called after load but before the node is shown on the add/edit form.
hook_validate in modules/node/node.api.php
Verify a node editing form.
node_assign_owner_action_validate in modules/node/node.module
node_validate in modules/node/node.module
Perform validation checks on the given node.
system_check_directory in modules/system/system.module
Checks the existence of the directory specified in $form_element. This function is called from the system_settings form to check both core file directories (file_public_path, file_private_path, file_temporary_path).
system_send_email_action_validate in modules/system/system.module
Validate system_send_email_action form submissions.
taxonomy_form_term_validate in modules/taxonomy/taxonomy.admin.inc
Validation handler for the term form.
taxonomy_form_vocabulary_validate in modules/taxonomy/taxonomy.admin.inc
Validation handler for the vocabulary form.
trigger_assign_form_validate in modules/trigger/trigger.admin.inc
Validation function for trigger_assign_form().
user_account_form_validate in modules/user/user.module
Form validation handler for user_account_form().
user_login_final_validate in modules/user/user.module
The final validation handler on the login form.
user_login_name_validate in modules/user/user.module
A FAPI validate handler. Sets an error if supplied username has been blocked.
user_validate_picture in modules/user/user.module

Code

includes/form.inc, line 945

<?php
function form_set_error($name = NULL, $message = '') {
  $form = &drupal_static(__FUNCTION__, 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
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.