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:
- 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.
- Create or edit a new Webform
- Under the "Webform advanced settings", enter the snippet, including the
<?php ?> tags.