FAQs

How can I attach files from my server to an email?

Written
ChronoForms makes it easy to attach uploaded files to an email but sometimes you need to attach a 'standard' file that hasn't been uploaded like a product brochure or terms and conditions. This FAQ gives you one way to do that.
The standard ChronoForms v4 email action makes it quite difficult to add a standard file to an email. If you use my custom {rokbox text=|Email [GH] action| size=|1000,600| }http://greyhead.net/how-to-docs/cfv4-email-gh-action{/rokbox} then you can add the path to a file on the server; or a comma separated list of paths to attach multiple files.

It is possible to use the standard Email action by using Custom Code to replicate the Uploaded File entries and 'fool' ChronoForms.

Attaching files depending on form data

This problem arises if, for example, you have a checkbox group in your form and want to attach files depending on which boxes are checked. Here is an example of the code that you might use in a Custom Code action to build a list of files to attach:
<?php
if ( !isset($form->data['checkboxes']) || count($form->data['checkboxes']) == 0 ) {
  return;
}
$files_array = array (
  1 => JPATH_SITE.'/some_path/some_file.pdf',
  2 => JPATH_SITE.'/some_path/some_other_file.pdf',
  . . .
);
$attach_files = array();
foreach ( $files_array as $k => $v ) {
  if ( in_array($k, $form->data['checkboxes']) ) {
    $attach_files[] = $v;
  }
}
$form->data['file_array'] = $attach_files;
?>
Note that this code needs to be customised. In particular the $files_array() should contain full paths of the files.
You can then add the special entry {file_array} in the attachments box of the Email [GH] action.