Hi Steve,
Here's the extract from Chapter 2 of The ChronoForms Book that talks about this
1. ChronoForms doesn't have a box that you can fill in to do this so we need to add some code to the OnSubmit Before box in the Form Editor.
If you already have code in the box – we added some in a previous recipe – that's fine. This code block can go before (or after) that one in the box. ChronoForms adds the form attachments to a $attachments array and we are going to add an extra entry to that. The code is short, once you know what it is:
<?php
$form_id = $MyForm->formrow->id;
$MyUploads =& CFUploads::getInstance($form_id);
$MyUploads->attachments[] = 'images/newsletter.pdf';
?>
Taking this line by line:
$form_id = $MyForm->formrow->id;
This gets the form ID, the entry you see in the first column of the Forms Manager. This is the internal identifier for the form and must be unique.
$MyUploads =& CFUploads::getInstance($form_id);
This gets a copy of a ChronoForms object that holds the uploads information for this form. In this case it's empty but if there had been files uploaded for the form, the information about them would be temporarily stored here.
$MyUploads->attachments[] = 'images'.DS.'newsletter.pdf';
This adds a new "upload" entry to the ChronoForms Uploads Object, though in this case it's not an upload but our static file. ChronoForms isn't fussy and will quite happily accept this.
Note that the path uses .DS. instead of / or \, because the Default Separator (DS) can vary depending on the server Joomla! adopts this more flexible version. We've used the partial path here 'images'.DS.'newsletter.pdf', to be a bit more thorough we could have added the fuller JPATH_ROOT.DS.'images'.DS.'newsletter.pdf'
With those three lines in place ChronoForms will attach the sample newsletter file to each e-mail that it sends out.
Note that if you have more than one e-mail setup then the file will be attached to both of them unless you disable attachments on one or the other. At the moment, there is no way of having two Email Setups with different file attachments (though it could be achieved by hand coding an e-mail setup).
Bob