Prevent email file link from showing

Fourmat 02 May, 2013
Hi there,

I have a form that has 7 file upload fields. Each of the fields is optional. I have created the email template so that the file link is created. When there is no file uploaded, the email template displays the code for the plugin:

{_PLUGINS_.upload_files.input_file_1.name}

in place of the missing file name. How can I prevent the display of this code of there is no file uploaded through this optional field?
Fourmat 03 May, 2013
Is there any way to add an if statement somewhere to determine if the

{_PLUGINS_.upload_files.input_file_1.name}

item is NULL or blank, and to not include it in the template if it is?
GreyHead 12 May, 2013
Hi fourmat,

I think that in this case I'd build the links block for the template in a Custom Code action before the Email action and include it into the Email template. Something like this:
<?php
$links = array;
if ( !isset($form->data['_PLUGINS_']['upload_files']) || !is_array($form->data['_PLUGINS_']['upload_files']) ) {
  return false;
}
$files =& $form->data['_PLUGINS_']['upload_files'];
for ( $i = 1; $i <= 7; $i++ ) {
  $input = 'input_file_'.$i;
  if ( isset($files[$input]['name']) && $files[$input]['name'] ) {
    $links[] = "<a href='{$files[$input]['name']}' >{$files[$input]['name']}</a>";
  }
}
$form->data['links'] = implode('<br />', $links);
?>
Then add {links} into the email template.

Bob
Fourmat 14 May, 2013
Great! I'll try it out and let you know how it goes. Thanks for your help!
This topic is locked and no more replies can be posted.