confirm_form

Versions
4.7
confirm_form($form_id, $form, $question, $path, $description = NULL, $yes = NULL, $no = NULL, $name = 'confirm')
5 – 7
confirm_form($form, $question, $path, $description = NULL, $yes = NULL, $no = NULL, $name = 'confirm')

Output a confirmation form

This function returns a complete form for confirming an action. A link is offered to go back to the item that is being changed in case the user changes his/her mind.

If the submit handler for this form is invoked, the user successfully confirmed the action. You should never directly inspect $_POST to see if an action was confirmed.

Note - if the parameters $question, $description, $yes, or $no could contain any user input (such as node titles or taxonomy terms), it is the responsibility of the code calling confirm_form() to sanitize them first with a function like check_plain() or filter_xss().

Parameters

$form Additional elements to inject into the form, for example hidden elements.

$question The question to ask the user (e.g. "Are you sure you want to delete the block <em>foo</em>?").

$path The page to go to if the user denies the action. Can be either a drupal path, or an array with the keys 'path', 'query', 'fragment'.

$description Additional text to display (defaults to "This action cannot be undone.").

$yes A caption for the button which confirms the action (e.g. "Delete", "Replace", ...).

$no A caption for the link which denies the action (e.g. "Cancel").

$name The internal name used to refer to the confirmation item.

Return value

The form.

Related topics

▾ 43 functions call confirm_form()

aggregator_admin_remove_feed in modules/aggregator/aggregator.admin.inc
block_custom_block_delete in modules/block/block.admin.inc
Menu callback; confirm deletion of custom blocks.
book_remove_form in modules/book/book.pages.inc
Menu callback; builds a form to confirm removal of a node from the book.
comment_confirm_delete in modules/comment/comment.admin.inc
Form builder; Builds the confirmation form for deleting a single comment.
comment_multiple_delete_confirm in modules/comment/comment.admin.inc
List the selected comments and verify that the admin wants to delete them.
contact_category_delete_form in modules/contact/contact.admin.inc
Form builder for deleting a contact category.
field_ui_field_delete_form in modules/field_ui/field_ui.admin.inc
Menu callback; present a form for removing a field from a content type.
filter_admin_delete in modules/filter/filter.admin.inc
Menu callback; confirm deletion of a format.
forum_confirm_delete in modules/forum/forum.admin.inc
Returns a confirmation page for deleting a forum taxonomy term.
image_effect_delete_form in modules/image/image.admin.inc
Form builder; Form for deleting an image effect.
image_style_delete_form in modules/image/image.admin.inc
Form builder; Form for deleting an image style.
image_style_revert_form in modules/image/image.admin.inc
Confirmation form to revert a database style to its default.
locale_date_format_reset_form in modules/locale/locale.module
Reset locale specific date formats to the global defaults.
locale_languages_delete_form in includes/locale.inc
User interface for the language deletion confirmation screen.
locale_translate_delete_form in includes/locale.inc
User interface for the string deletion confirmation screen.
menu_delete_menu_confirm in modules/menu/menu.admin.inc
Build a confirm form for deletion of a custom menu.
menu_item_delete_form in modules/menu/menu.admin.inc
Build a confirm form for deletion of a single menu link.
menu_reset_item_confirm in modules/menu/menu.admin.inc
Menu callback; reset a single modified menu link.
node_configure_rebuild_confirm in modules/node/node.admin.inc
Menu callback: confirm rebuilding of permissions.
node_delete_confirm in modules/node/node.pages.inc
Menu callback -- ask for confirmation of node deletion
node_multiple_delete_confirm in modules/node/node.admin.inc
node_revision_delete_confirm in modules/node/node.pages.inc
node_revision_revert_confirm in modules/node/node.pages.inc
Ask for confirmation of the reversion to prevent against CSRF attacks.
node_type_delete_confirm in modules/node/content_types.inc
Menu callback; delete a single content type.
openid_user_delete_form in modules/openid/openid.pages.inc
Menu callback; Delete the specified OpenID identity from the system.
path_admin_delete_confirm in modules/path/path.admin.inc
Menu callback; confirms deleting an URL alias
profile_field_delete in modules/profile/profile.admin.inc
Menu callback; deletes a field from all user profiles.
scaffolding_example_delete_confirm in developer/examples/scaffolding_example/scaffolding_example.admin.inc
Build the delete confirmation form.
search_reindex_confirm in modules/search/search.admin.inc
Menu callback: confirm wiping of the index.
shortcut_link_delete in modules/shortcut/shortcut.admin.inc
Menu callback; Build the form for deleting a shortcut link.
system_actions_delete_form in modules/system/system.admin.inc
Create the form for confirmation of deleting an action.
system_date_delete_format_form in modules/system/system.admin.inc
Menu callback; present a form for deleting a date format.
system_delete_date_format_type_form in modules/system/system.admin.inc
Menu callback; present a form for deleting a date type.
system_ip_blocking_delete in modules/system/system.admin.inc
IP deletion confirm page.
system_modules_confirm_form in modules/system/system.admin.inc
Display confirmation form for required modules.
system_modules_uninstall_confirm_form in modules/system/system.admin.inc
Confirm uninstall of selected modules.
taxonomy_term_confirm_delete in modules/taxonomy/taxonomy.admin.inc
Form builder for the term delete form.
taxonomy_term_confirm_parents in modules/taxonomy/taxonomy.admin.inc
Form builder for the confirmation of multiple term parents.
taxonomy_vocabulary_confirm_delete in modules/taxonomy/taxonomy.admin.inc
Form builder for the vocabulary delete confirmation form.
taxonomy_vocabulary_confirm_reset_alphabetical in modules/taxonomy/taxonomy.admin.inc
Form builder to confirm resetting a vocabulary to alphabetical order.
trigger_unassign in modules/trigger/trigger.admin.inc
Confirm removal of an assigned action.
user_cancel_confirm_form in modules/user/user.pages.inc
Form builder; confirm form for cancelling user account.
user_multiple_cancel_confirm in modules/user/user.module

Code

modules/system/system.module, line 2542

<?php
function confirm_form($form, $question, $path, $description = NULL, $yes = NULL, $no = NULL, $name = 'confirm') {
  $description = isset($description) ? $description : t('This action cannot be undone.');

  // Prepare cancel link.
  if (isset($_GET['destination'])) {
    $options = drupal_parse_url(urldecode($_GET['destination']));
  }
  elseif (is_array($path)) {
    $options = $path;
  }
  else {
    $options = array('path' => $path);
  }
  $cancel = l($no ? $no : t('Cancel'), $options['path'], $options);

  drupal_set_title($question, PASS_THROUGH);

  // Confirm form fails duplication check, as the form values rarely change -- so skip it.
  $form['#skip_duplicate_check'] = TRUE;

  $form['#attributes'] = array('class' => array('confirmation'));
  $form['description'] = array('#markup' => $description);
  $form[$name] = array('#type' => 'hidden', '#value' => 1);

  $form['actions'] = array('#prefix' => '<div class="container-inline">', '#suffix' => '</div>');
  $form['actions']['submit'] = array('#type' => 'submit', '#value' => $yes ? $yes : t('Confirm'));
  $form['actions']['cancel'] = array('#markup' => $cancel);
  // By default, render the form using theme_confirm_form().
  if (!isset($form['#theme'])) {
    $form['#theme'] = 'confirm_form';
  }
  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.