0

I have a custom mail template in Webform so values can be in a table for copying/pasting into Excel.

I want the value of the select option fields instead of the key (doing manual entry for webform creators would be too tedious). I can't seem to get to those values.

Any help would be appreciated.

Here's my current code for webform-mail.tpl.php:

<h2>
<?php
    print $node->title;
?>
</h2>

<?php print ($email['html'] ? '<p>' : '') . t('Submitted on [submission:date:long]'). ($email['html'] ? '</p>' : ''); ?>

<table style="border: 1px solid black; border-collapse: collapse;">
<?php
foreach ($node->webform['components'] as $key => $component) {
    if (isset($submission->data[$key][0])) {
   $key_converted = ucwords(str_replace('_',' ', $node->webform['components'][$key]['form_key']));
    print '<tr><td style="border: 1px solid black;">'. $key_converted .'<td style="border: 1px solid black;">' . ($submission->data[$key][0]) . "</td></tr>";
}
}
?>
</table>
0

For anyone else that runs across this:

<h2>
<?php
print $node->title;
?>
</h2>

<?php print ($email['html'] ? '<p>' : '') . t('Submitted on [submission:date:long]'). ($email['html'] ? '</p>' : ''); ?>


<table style="border: 1px solid black; border-collapse: collapse;">
<?php
foreach ($node->webform['components'] as $key => $component) {
   if (isset($submission->data[$key][0])) {
     $key_converted = ucwords(str_replace('_',' ', $node->webform['components'][$key]['form_key']));
     $submittedvalue = $submission->data[$key][0];

     if (isset($submittedvalue)) {
       print '<tr><td style="border: 1px solid black;">'. $key_converted .'</td><td style="border: 1px solid black;">';
       if ($node->webform['components'][$key]['type'] != "select") {
           print $submittedvalue;
       }
       else {
        $selectlistitems = explode("|", $node->webform['components'][$key]['extra']['items']);
        if (is_numeric($submittedvalue)) {
                print $selectlistitems[$submittedvalue];
        }
        else {
                 print $submittedvalue;
        }
       }
       print '</td></tr>';
       }
  }
}
?>
</table>

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.