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().
$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.
The form.
modules/system/system.module, line 2656
<?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);
$form['#attributes'] = array('class' => array('confirmation'));
$form['description'] = array('#markup' => $description);
$form[$name] = array('#type' => 'hidden', '#value' => 1);
$form['actions'] = array(
'#type' => 'container',
'#attributes' => array('class' => array('form-actions', 'container-inline')),
);
$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;
}
?>