Hi,

I have a webform mail.tpl.php set up to customize the display of email sent once a webform on the site is submitted. I'm using code like this to display the submitted data in the template:

(Preferred Starting Date: <?php echo $form_values['submitted'][1]; ?>

Which works fine unless the submitted field is from a multi-select list or a date, in which case the email shows the submitted field as

(Preferred Starting Date: Array)

What do I need to use instead of $form_values['submitted'][field_id] to get the array values to display in the email message?

Thanks!

Comments

paul-c’s picture

Bumping this - any ideas/suggestions?

stoob’s picture

use print_r($array) to see the full structure of your array so you know what to print

land0’s picture

This is what I have added to my mail template file.
<?php print $form_values['submitted']['23']; ?>
Which returns
Deserts: Array
in the email that is sent.
So what I did was
<?php print_r($form_values['submitted']['23']); ?>
Which returns the following in the email that is sent:

Array
(
[Cookies And Brownies] => Cookies And Brownies
[Apple Pies And Chocolate Cakes] => Apple Pies And Chocolate Cakes
[Carmel Apple Cobbler] => Carmel Apple Cobbler
)

Which is the closest I have come to printing the actual selected values from the form. I have tried all of the various strings that I could find in the forums asked on IRC I am at a loss. :( It is amazing how something that should be completely mundane and simple is made to be so seemingly impossible to overcome. Sadly it is fragmented modules like Webform that bring Drupal down a notch.

If someone knows what php string I need to use to get the array of selected items to be properly displayed in the email I would really appreciate it. In fact I would be willing to pay $20 for the correct working solution. :)

pfrenssen’s picture

Try something like this:

print('<ul>');
foreach($form_values['submitted']['23'] as $value) {
  print("<li>$value</li>");
}
print('</ul>');
land0’s picture

And the $20 goes to pfrenssen. Thank you so very much.

stephenrobinson’s picture

echo ('<pre>'.htmlspecialchars(print_r($form_values['submitted'][1],1)).'</pre>');