How can I store the user agent string and referrer for Webform 4.x submissions? In Webform 3.x, I have a "Give me feedback" webform that I embed in various places throughout my site using Panels.  This form contains two hidden fields:

Referer / Default value: %server[HTTP_REFERER]

User agent / Default value: %server[HTTP_USER_AGENT]

This is extremely helpful because I can get the details of users' machines without having to ask them as well as get the page the user came from (because the webform is embedded on a number of pages throughout my site with Panels).  However, %server\[\] tokens apparently no longer work in Webform 4.x:


  Most tokens will be upgraded for you, however some tokens do not have
  equivalents and no longer work. These include %post, %request,
  %cookie, and %session. The %get token (which maps to PHP's $_GET
  variable) has the equivalent token [current-page:query:key].


Is there an alternate way to somehow include the user agent string and referer in a 4.x webform?
This issue is Closed (won't fix) on Drupal.org

If you want them back, you basically need to create a module that implements hook_tokens() and hook_token_info(), as described in the API. I don't think anyone did it already.

Here is how I'd do it:

function yourmodule_token_info() {
  $type = array(
    'name' =&gt; t('Server'),
    'description' =&gt; t('Tokens related to $_SERVER superglobal.'),
  );
  $tokens = array();
  foreach($_SERVER as $key =&gt; $val) { //discard $val now
    $tokens[$key] = array(
      'name' =&gt; $key,
      'description' =&gt; "\$_SERVER['$key']",
    );
  }
  return array(
    'types' =&gt; array('server' =&gt; $type),
    'tokens' =&gt; array('server' =&gt; $tokens),
  );
}

function yourmodule_tokens($type, $tokens, array $data = array(), array $options = array()) {
  if($type == 'server') {
    $replacements = array();
    foreach ($tokens as $name =&gt; $original) {
        $replacements[$original] = (string)$_SERVER[$name];
    }
    return $replacements;
  }
}


Of course code above is not production ready, it ignores proper type handling, security issues and so on. It's meant to set you on the right track, but you need to apply your own sanity before deploying it. I take no responsibility for abuse. Read about the reasons it was removed in the first place before you decide to add it back, and be careful to restore only what you really need.