Add a submit confirmation form in Drupal 6.
by rayasa on Tue, 03/20/2012 - 13:14
In Drupal sometimes it may get difficult to figure out the way to get what you want, but once you know you'll only appreciate how its done. Adding a confirmation page is one of such tasks that apparantly appears out of the normal flow, though considering that a confirmation page is not a full fledged form but just a buffer, it cannot be handled better.
The trick is, on a form submit we use the $form_state['rebuild'] to indicate that the original form needs to be rebuilt and build a confirmation page instead. We use the form_state['storage'] to hold on to the submitted values and use it after submit approval to process the form further.
The following is a sample code that implements a confirmation page. The original form is a custom webform submission approval queue that lists all the submissions as a table with a checkbox to select those that are approved. Once the moderator hits the submit button he gets an confirmation page that finalizes the acceptance of the submissions. Please visit the api page for confirm_form to learn more about the function's signature.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | /** * Form to list all submissions pending approval. */function custom_module_webform_contact_approval_queue($form_state, $node) { // HERE WE CHECK IF THE FORM IS BUILDING WITH // A CONFIRMATION REQUIREMENT. if(isset($form_state['storage']['confirm'])) { $form = array(); return confirm_form($form, t('Confirm to send'), 'node/' . $node->nid . '/webform-results/approval_queue', '', t('Send'), t('No, wait!')); } // BULD THE ORIGINAL FORM HERE}/** * Submit handler for the submission approval queue form. */function custom_module_webform_contact_approval_queue_submit($form, &$form_state) { // ANY SUBMISSION OF THIS FORM REQUIRES A CONFIRMATION BEFORE ITS PROCESSED. // THEREFORE, INDICATE THAT THE FORM NEEDS TO BE REBUILT AS A CONFIRMATION PAGE. // ALSO, STORE THE CURRENT SELECTIONS TO BE PROCESSED AFTER CONFIRMATION. if (!isset($form_state['storage']['confirm'])) { foreach ($form_state['values']['approve'] as $sid => $approved) { if ($approved) { $form_state['storage']['submissions'][$sid] = $form['#submissions'][$sid]; } } $form_state['storage']['node'] = $form['#node']; $form_state['storage']['confirm'] = TRUE; $form_state['rebuild'] = TRUE; } // IF CONFIRMATION GRANTED PROCEED WITH SUBMISSION ACCEPTANCE. } |
Post new comment