I'm using Webform 4. It uses Drupal's tokens, not it's own % tokens like it used to in version 3, and pretty much all what I found was about webform 3.
Say I want to make multi-page subscription form. On first page there is only an email field. On second one, I want a markup that will say something like:
Detailed subscription configuration for molot@example.com
Similarly, I'd like to be able to use them as default values for future fields, like asking user for billing address, and then for delivery address.
Are there any tokens for that? What I did for now is:
function mymodule_token_info() {
$type = array(
'name' => t('Webform submitted values'),
'description' => t('Tokens related to $_POST[\'submitted\'].'),
);
$tokens = array();
if(isset($_POST['submitted'])) {
foreach($_POST['submitted'] as $key => $val) { //discard $val now
$tokens[$key] = array(
'name' => $key,
'description' => "\$_POST['submitted']['$key']",
);
}
}
return array(
'types' => array('webform_submitted' => $type),
'tokens' => array('webform_submitted' => $tokens),
);
}
function mymodule_tokens($type, $tokens, $data, $options) {
if($type == 'webform_submitted') {
$replacements = array();
foreach ($tokens as $name => $original) {
//Hide errors below. We don't care if it really exists yet. If empty, so be it.
@$replacements[$original] = (string)$_POST['submitted'][$name];
}
return $replacements;
}
}
It works, but it only shows values from one step earlier, so requires some dirty tricks with hidden fields to carry email value across multiple steps. I admit - it was just quick and dirty. Is there any built-in way to do it, or properly maintained contributed module for this? Or a way to make this code work independently of $_POST['submitted']
, to make it carry values across many steps and to make it's tokens (from available Webform elements) visible on token list in edit windows?