Webform Additional Submission Snippets

You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules

This is a collection of PHP snippets that you can use to add custom submission handling to your Webforms. Using submission code, you can change any of the $form_values or $form_state variables that are available to you, and these values will be saved with the changed values in the database.

Please note: Webform version 3 no longer supports additional validation and additional processing snippets. For more information about support for PHP code execution, see http://drupal.org/node/754580 and http://drupal.org/project/webform_php.

A strange Webform quirk: Values are split between $form_values['submitted'] and $form_values['submitted_tree']. Values set in the 'submitted' key are saved to the database, while values in the 'submitted_tree' are sent out in the sent e-mails. The submitted tree will follow the same format as your form (that is, fields will be nested), but the 'submitted' values will be a single array, keyed by the unique component ID for each field.

An example:

$component_key = 'first_name';
$component_cid = 6;

// The First Name field is within a fieldset for "Name".
// Updating this value will set the first name to to "Bob" in the e-mail.
$form_values['submitted_tree']['name'][$component_key] = 'Bob';

// Despite the field being in a fieldset, in the submitted array,
// it is identified directly by the component CID.
// Updating this value will set the the first name to be "Joe" in the database.
$form_values['submitted'][$component_cid] = 'Joe';

or if you just wanted to set the value to a php variable:


$first_name = $form_values['submitted_tree']['first_name'];
$last_name= $form_values['submitted_tree']['last_name'];

This snippets are only intended for use with the Webform 2.x module. They will not work with CCK or other modules.

To use any of these snippets:

  1. Visit the permissions page (admin/user/access in D5 or admin/user/permissions in D6) and ensure the current user has the "use PHP for additional processing" permission.
  2. Create or edit a new Webform
  3. Under the "Webform advanced settings", enter the snippet, including the <?php ?> tags.

Additional Processing Field - Resize uploaded image

This additional processing snippet makes it possible to resize an image uploaded through a Webform file component. This assumes you've

Redirect to Dynamic URL

By setting the $node->webform['confirmation'] key, you can change where Webform redirects the user after form processing has been completed.

Sending confirmation email

To send a confirmation email via additional processing you can use the script below.

Guide maintainers

quicksketch's picture