I created a theme file called webform-mail-54.tpl.php

Everything is working as intended. As I also need to allow users to upload files I used file filed but I'm don't know what should I use in the webform-mail-54.tpl.php?

I tried:
Attach File: echo $form_values['submitted_tree']['name_and_contact_information']['attach_file']; but in the mail that I got it shows some variables only and not the image or a link?

Does anyone know how can this be done in theme tpl.php file?


GreenStage’s picture

I also want to do this, but have no idea how to theme this part of the tpl file. I'm not much of an expert with PHP :)

When someone uploads an image, I want the email to simply add a link to the uploaded file.

<?php print_r($form_values) ?>
shows the form field variables as:
[file_upload] => a:5:{s:8:"filename";s:19:"my-file.JPG";s:8:"filepath";s:37:"files/webform/art/my-file.JPG";s:8:"filemime";s:11:"image/pjpeg";s:8:"filesize";s:6:"665687";s:6:"source";s:11:"file_upload";}1

If I add
to the tpl file, I get this:

What I want is just a link to the file.

I'm assuming I am missing something in the "$form_values['submitted']['file_upload']" instruction, but have no idea what.

Help is much appreciated.

quicksketch’s picture

Thanks, it looks like this could potentially be a bug in Webform's file field (not entirely sure at this point if it's intentional or not). The data in the file field is "serialized", that is, it's an array of more data stored as a string. You can create a link with the following code:

$file = unserialize($form_values['submitted_tree']['name_and_contact_information']['attach_file']);

echo url($file['filepath'], NULL, NULL, TRUE); // Make the link absolute (Drupal 5).

echo url($file['filepath'], array('absolute' => TRUE)); // Make the link absolute (Drupal 6).

You'll use only one of the echo lines above, depending on which version of Drupal you're using.

quicksketch’s picture

Status: Active » Closed (fixed)