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

▾ 78 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.
aggregator_form_opml_validate in modules/aggregator/aggregator.admin.inc
Validate aggregator_form_opml form submissions.
authorize_filetransfer_form_validate in includes/authorize.inc
Validate callback for the filetransfer authorization form.
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_form_validate in modules/comment/comment.module
Validate comment form submissions.
contact_category_edit_form_validate in modules/contact/contact.admin.inc
Validate the contact category edit page form submission.
contact_personal_form_validate in modules/contact/contact.pages.inc
Form validation handler for contact_personal_form().
contact_site_form_validate in modules/contact/contact.pages.inc
Form validation handler for contact_site_form().
dblog_filter_form_validate in modules/dblog/dblog.admin.inc
Validate result from dblog administration filter form.
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.
field_ui_field_edit_form_validate in modules/field_ui/field_ui.admin.inc
Validate a field's settings.
file_managed_file_save_upload in modules/file/file.module
Given a managed_file element, save any files that have been uploaded into it.
file_save_upload in includes/file.inc
Saves a file upload to a new location.
filter_admin_format_form_validate in modules/filter/filter.admin.inc
Validate text 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_node_validate in modules/forum/forum.module
Implement hook_node_validate().
hook_node_validate in modules/node/node.api.php
Perform node validation before a node is created or updated.
hook_prepare in modules/node/node.api.php
Act on a node object about to be shown on the add/edit form.
hook_validate in modules/node/node.api.php
Perform node validation before a node is created or updated.
image_gd_settings in modules/system/image.gd.inc
Retrieve settings for the GD2 toolkit.
image_gd_settings_validate in modules/system/image.gd.inc
Validate the submitted GD settings.
image_style_name_validate in modules/image/image.admin.inc
Element validate function to ensure unique, URL safe style names.
install_settings_form_validate in ./install.php
Form API validate for install_settings form.
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.
locale_translation_filter_form_validate in includes/locale.inc
Validate result from locale translation filter form.
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.
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 URL alias is valid
path_form_element_validate in modules/path/path.module
Form element validation handler for URL alias form element.
poll_validate in modules/poll/poll.module
Implement 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_user_form_validate in modules/profile/profile.module
Form validation handler for the user register/profile form.
search_form_submit in modules/search/search.pages.inc
Process a search form submission.
shortcut_link_edit_validate in modules/shortcut/shortcut.admin.inc
Validation handler for the shortcut link add and edit forms.
system_add_date_formats_form_validate in modules/system/system.admin.inc
Validate new date format string submission.
system_add_date_format_type_form_validate in modules/system/system.admin.inc
Validate system_add_date_format_type form submissions.
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_ip_blocking_form_validate in modules/system/system.admin.inc
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 form.
taxonomy_form_vocabulary_validate in modules/taxonomy/taxonomy.admin.inc
Validation handler for the vocabulary form.
translation_node_validate in modules/translation/translation.module
Implement hook_node_validate().
trigger_assign_form_validate in modules/trigger/trigger.admin.inc
Validation function for trigger_assign_form().
update_manager_install_form_submit in modules/update/update.manager.inc
Handle form submission when installing new projects via the update manager.
update_manager_install_form_validate in modules/update/update.manager.inc
Validate the form for installing a new project via the update manager.
update_manager_update_form_validate in modules/update/update.manager.inc
Validation callback to ensure that at least one project is selected.
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_account_form_validate in modules/user/user.module
Form validation handler for user_account_form().
user_admin_account_validate in modules/user/user.admin.inc
user_admin_role_validate in modules/user/user.admin.inc
user_admin_settings in modules/user/user.admin.inc
Form builder; Configure user settings for this site.
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_pass_validate in modules/user/user.pages.inc
user_validate_picture in modules/user/user.module
_field_ui_field_overview_form_validate_add_existing in modules/field_ui/field_ui.admin.inc
Helper function for field_ui_field_overview_form_validate.
_field_ui_field_overview_form_validate_add_new in modules/field_ui/field_ui.admin.inc
Helper function for field_ui_field_overview_form_validate.

Code

includes/form.inc, line 966

<?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.