Confirmation Page Usage of Form Components or Variables

Last modified: October 10, 2009 - 04:22

It should be easier to format the confirmation page and capture form entries. Ideally, you would have access to all the form variables, and you could do this in a confirmation-page.tpl.php as well as in the confirmation page window under [webform]:Edit:Configuration. It took me a long time to find this tip on how to access form variables in confirmation pages.

Here is a very simple example to get you started, that I adapted from the above tip. Permit PHP code in your format and insert the following in the confirmation window of your [webform]:Edit:Configuration.

<?php
include_once(drupal_get_path('module', 'webform') .'/webform_submissions.inc');
$nid = arg(1); // need to hard-code nid if this is a custom page
$sid = $_GET['sid'];
$submission = webform_get_submission($nid, $sid);

$first_name = $submission->data[6]['value'][0];
$last_name = $submission->data[7]['value'][0];
$thanks = $first_name . " " . $last_name;
?>


<h2>Thank you <?php print $thanks ?>... Your registration has been sent.</h2>

So, in my form I created a Form Component called "Last Name", identified by Field Key "last_name" (See "Edit Component: Advanced settings"). But, if I want to use it in the Confirmation Message block, I need to first get the submission using "node id" and "submission id", which then gives me access to an array of my field:values. Use data[6] ['value'] to address the array to get the first_name.

The difficulty here is that you have to address your form fields numerically. This means you need to get a copy of your form data structure, which is possible using the procedure suggested in "THEMING.TXT" in your webform module folder:

Copy (do not move!) the "webform-mail.tpl.php" file to your theme directory.
...
To get a better idea of what variables are available to you, you can include the print_r function in your email. Simply include the line [at the bottom of the file]:

<?php
print_r
($form_values)
?>

to get a listing of all the available fields you can use in your mail.

This will printout (via email of your form submission) both the numeric:value and the field:value data structures of your form that you need to identify your variables. I munged these into excel so I can see at a glance the numeric array, the form component, and a typical value.

 
 

Drupal is a registered trademark of Dries Buytaert.