function form_example_tutorial_11_confirm_name
Example 11: A form generated with confirm_form().
This function generates the confirmation form using the confirm_form() function. If confirmed, it sets a drupal message to demonstrate it's success.
Parameters
string $name: The urlencoded name entered by the user.
See also
form_example_tutorial_11_confirm_name_submit()
Related topics
1 string reference to 'form_example_tutorial_11_confirm_name'
- form_example_menu in form_example/
form_example.module - Implements hook_menu().
File
-
form_example/
form_example_tutorial.inc, line 862
Code
function form_example_tutorial_11_confirm_name($form, $form_state, $name) {
// confirm_form() returns a complete form array for confirming an action.
// It has 7 arguments: $form, $question, $path, $description, $yes, $no, and
// $name.
// - $form: Additional elements to add to the form that will be available in
// the submit handler.
// - $question: What is the user confirming? This will be the title of the
// page.
// - $path: Where should the page go if the user hits cancel?
// - $description = NULL: Additional text to display.
// - $yes = NULL: Anchor text for the confirmation button. Defaults to
// t('Confirm').
// - $no = NULL: Anchor text for the cancel link. Defaults to t('Cancel').
// - $name = 'confirm': The internal name used to refer to the confirmation
// item.
// First we make a textfield for our user's name. confirm_form() allows us to
// Add form elements to the confirmation form, so we'll take advangage of
// that.
$user_name_text_field = array(
'name' => array(
'#type' => 'textfield',
// We don't want the user to be able to edit their name here.
'#disabled' => TRUE,
'#title' => t('Your name:'),
'#value' => urldecode($name),
),
);
// The question to ask the user.
$confirmation_question = t('Is this really your name?');
// If the user clicks 'no,' they're sent to this path.
$cancel_path = 'examples/form_example/tutorial/11';
// Some helpful descriptive text.
$description = t('Please verify whether or not you have input your name correctly. If you verify you will be sent back to the form and a message will be set. Otherwise you will be sent to the same page but with no message.');
// These are the text for our yes and no buttons.
$yes_button = t('This is my name');
$no_button = t('Nope, not my name');
// The name Form API will use to refer to our confirmation form.
$confirm_name = 'confirm_example';
// Finally, call confirm_form() with our information, and then return the form
// array it gives us.
return confirm_form($user_name_text_field, $confirmation_question, $cancel_path, $description, $yes_button, $no_button, $confirm_name);
}