function confirm_form

7.x system.module confirm_form($form, $question, $path, $description = NULL, $yes = NULL, $no = NULL, $name = 'confirm')
6.x system.module confirm_form($form, $question, $path, $description = NULL, $yes = NULL, $no = NULL, $name = 'confirm')

Generates a form array for a confirmation form.

This function returns a complete form array for confirming an action. The form contains a confirm button as well as a cancellation link that allows a user to abort the action.

If the submit handler for a form that implements confirm_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 add to the form. These can be regular form elements, #value elements, etc., and their values will be available to the submit handler.

$question: The question to ask the user (e.g. "Are you sure you want to delete the block <em>foo</em>?"). The page title will be set to this value.

$path: The page to go to if the user cancels the action. This can be either:

  • A string containing a Drupal path.
  • An associative array with a 'path' key. Additional array values are passed as the $options parameter to l().

If the 'destination' query parameter is set in the URL when viewing a confirmation form, that value will be used instead of $path.

$description: Additional text to display. Defaults to t('This action cannot be undone.').

$yes: A caption for the button that confirms the action (e.g. "Delete", "Replace", ...). Defaults to t('Confirm').

$no: A caption for the link which cancels the action (e.g. "Cancel"). Defaults to t('Cancel').

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

Return value

The form array.

43 calls to confirm_form()
aggregator_admin_remove_feed in drupal-7.x/modules/aggregator/aggregator.admin.inc
Deletes a feed.
block_custom_block_delete in drupal-7.x/modules/block/block.admin.inc
Form constructor for the custom block deletion form.
book_remove_form in drupal-7.x/modules/book/book.pages.inc
Form constructor to confirm removal of a node from a book.
comment_confirm_delete in drupal-7.x/modules/comment/comment.admin.inc
Form builder; Builds the confirmation form for deleting a single comment.
comment_multiple_delete_confirm in drupal-7.x/modules/comment/comment.admin.inc
List the selected comments and verify that the admin wants to delete them.

... See full list

1 string reference to 'confirm_form'
system_theme in drupal-7.x/modules/system/system.module
Implements hook_theme().

File

drupal-7.x/modules/system/system.module, line 2847
Configuration system that lets administrators modify the workings of the site.

Code

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

  drupal_set_title($question, PASS_THROUGH);

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

  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => $yes ? $yes : t('Confirm'),
  );
  $form['actions']['cancel'] = array(
    '#type' => 'link',
    '#title' => $no ? $no : t('Cancel'),
    '#href' => $options['path'],
    '#options' => $options,
  );
  // By default, render the form using theme_confirm_form().
  if (!isset($form['#theme'])) {
    $form['#theme'] = 'confirm_form';
  }
  return $form;
}