Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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?
Comments
Comment #1
GreenStage CreditAttribution: GreenStage commentedI 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
$form_values['submitted']['file_upload']
to the tpl file, I get this:
a:5:{s:8:"filename";s:19:"my-fileJPG";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
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.
Comment #2
quicksketchThanks, 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:
You'll use only one of the echo lines above, depending on which version of Drupal you're using.
Comment #3
quicksketch