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

▾ 66 functions call 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.
book_admin_settings_validate in modules/book/book.admin.inc
Validate the book settings form.
comment_admin_overview_validate in modules/comment/comment.admin.inc
Validate comment_admin_overview form submissions.
comment_validate in modules/comment/comment.module
Validate comment data.
contact_admin_edit_validate in modules/contact/contact.admin.inc
Validate the contact category edit page form submission.
contact_mail_page_validate in modules/contact/contact.pages.inc
Validate the site-wide contact page form submission.
dblog_filter_form_validate in modules/dblog/dblog.admin.inc
Validate result from dblog administration filter form.
do_search in modules/search/search.module
Do a query on the full-text search index for a word or words.
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_check_directory in includes/file.inc
Check that the directory exists and is writable. Directories need to have execute permissions to be considered a directory by FTP servers, etc.
file_save_upload in includes/file.inc
Saves a file upload to a new location. The source file is validated as a proper upload and handled as such.
filter_admin_format_form_validate in modules/filter/filter.admin.inc
Validate filter format form submissions.
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.
forum_nodeapi in modules/forum/forum.module
Implementation of hook_nodeapi().
hook_prepare in developer/hooks/node.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 developer/hooks/node.php
Verify a node editing form.
image_gd_settings in includes/image.gd.inc
Retrieve settings for the GD2 toolkit.
image_gd_settings_validate in includes/image.gd.inc
Validate the submitted GD settings.
locale_languages_edit_form_validate in includes/locale.inc
Validate the language editing form. Reused for custom language addition too.
locale_languages_predefined_form_validate in includes/locale.inc
Validate the language addition form.
locale_translate_edit_form_validate in includes/locale.inc
Validate string editing form submissions.
menu_edit_item_validate in modules/menu/menu.admin.inc
Validate form values for a menu link being added or edited.
menu_edit_menu_validate in modules/menu/menu.admin.inc
Validates the human and machine-readable names when adding or editing a menu.
multipage_form_example_custom_validate in developer/examples/multipage_form_example.module
Validate our form.
nodeapi_example_nodeapi in developer/examples/nodeapi_example.module
Implementation of hook_nodeapi().
node_admin_nodes_validate in modules/node/node.admin.inc
Validate node_admin_nodes form submissions.
node_assign_owner_action_validate in modules/node/node.module
node_example_validate in developer/examples/node_example.module
Implementation of hook_validate().
node_type_form_validate in modules/node/content_types.inc
Validates the content type submission form generated by node_type_form().
node_validate in modules/node/node.module
Perform validation checks on the given node.
openid_begin in modules/openid/openid.module
The initial step of OpenID authentication responsible for the following:
openid_user_add_validate in modules/openid/openid.pages.inc
path_admin_form_validate in modules/path/path.admin.inc
Verify that a new URL alias is valid
path_nodeapi in modules/path/path.module
Implementation of hook_nodeapi().
poll_validate in modules/poll/poll.module
Implementation of hook_validate().
poll_view_voting_validate in modules/poll/poll.module
Validation function for processing votes
profile_field_form_validate in modules/profile/profile.admin.inc
Validate profile_field_form submissions.
profile_validate_profile in modules/profile/profile.module
search_form_submit in modules/search/search.pages.inc
Process a search form submission.
system_send_email_action_validate in modules/system/system.module
Validate system_send_email_action form submissions.
system_site_information_settings_validate in modules/system/system.admin.inc
Validate the submitted site-information form.
taxonomy_form_term_validate in modules/taxonomy/taxonomy.admin.inc
Validation handler for the term edit form. Ensure numeric weight values.
taxonomy_node_validate in modules/taxonomy/taxonomy.module
Make sure incoming vids are free tagging enabled.
throttle_admin_settings_validate in modules/throttle/throttle.admin.inc
trigger_assign_form_validate in modules/trigger/trigger.admin.inc
Validation function for trigger_assign_form().
update_settings_validate in modules/update/update.settings.inc
Validation callback for the settings form.
upload_admin_settings_validate in modules/upload/upload.admin.inc
Form API callback to validate the upload settings form.
upload_js in modules/upload/upload.module
Menu-callback for JavaScript-based uploads.
user_admin_access_check_validate in modules/user/user.admin.inc
user_admin_account_validate in modules/user/user.admin.inc
user_admin_role_validate in modules/user/user.admin.inc
user_authenticate in modules/user/user.module
Try to log in the user locally.
user_edit_validate in modules/user/user.pages.inc
user_login_final_validate in modules/user/user.module
A validate handler on the login form. Should be the last validator. Sets an error if user has not been authenticated yet.
user_login_name_validate in modules/user/user.module
A FAPI validate handler. Sets an error if supplied username has been blocked or denied access.
user_pass_validate in modules/user/user.pages.inc
user_profile_form_validate in modules/user/user.pages.inc
Validation function for the user account and profile editing form.
user_validate_picture in modules/user/user.module
_install_settings_form_validate in ./install.php
Helper function for install_settings_validate.
_user_edit_validate in modules/user/user.module

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
 
 

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.