1

I have a webform that sends an email. The webform has a date field and I need to format that date field.

I have tried:

[submission:values:date_field:CUSTOM_FORMAT]
[submission:values:date_field:long]
[submission:values:date_field:value:custom:d-M-y]

Both result in a blank date.

How can I format the date in a webform email using a non-default (which appears to be short) date format?

1

I had to create a custom hook_tokens function:

/**
 * Implementation of hook_tokens().
 */
function MODULE_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  if ($type == 'submission' && !empty($data['webform-submission'])) {
    $node = isset($data['node']) ? $data['node'] : node_load($submission->nid);

    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'values:date_field:custom_format':
          foreach ($node->webform['components'] as $cid => $component) {
            if ($component['form_key'] == 'date_field') {
              $replacements[$original] = format_date(strtotime($data['webform-submission']->data[$cid][0]), 'custom_format');
            }
          }
          break;
      }
    }
  }

  return $replacements;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.