Forums

Attach previously uploaded files to email

mypethamster 09 May, 2012
How do you attach images, word.doc to a a email, that are previously saved to folder, and names stored in database, but! are only sent when when all details are supplied and email sent as finalisation email.

All the details are currently stored in hidden inputs, including image, word.doc filenames, I would guess as hidden input these are sent as $_POST and not $_FILE, So how/where do i code these, in such a way that chronoforms will send as email attachment through $_FILE, I guess this would be done within OnSubmit before email, yes!

TIA
MPH

Edit: No it is not version 4, but V3. RC5 I think if i remember rightly
GreyHead 18 May, 2012
Hi MyPetHapmster,

From Chapter 2 of the ChronoForms Book

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.

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'.DS.'newsletter.pdf';
?>

Bob
mypethamster 19 May, 2012
OK! this is helpful, just a few questions.

Is there a way to reference upload directory, I did not use default, OR is that what .DS. would be a reference to the directory I used?

$MyUploads->attachments[] = 'images'.DS.'newsletter.pdf';

if I wish add attachment fields values form POST array file names, 4 in all, and some of these maybe empty, say 2 and 3, and i use

$MyUploads->attachments[] = 'uploadfolder/'.$_POST['upload1'];
$MyUploads->attachments[] = 'uploadfolder/'.$_POST['upload2'];
$MyUploads->attachments[] = 'uploadfolder/'.$_POST['upload3'];
$MyUploads->attachments[] = 'uploadfolder/'.$_POST['upload4'];

would this cause any problems, or would i need to filter out the empty POST values.
GreyHead 19 May, 2012
Hi MyPetHamster ,

DS is the Joomla! defined term for the 'Directory separator' or / or \ - if you use DS you avoid problems if the server expects a \ and gets a / instead.

The path can be anything you like, but usually the folder you are uploading the files to.

You should be neat and clean out the empty files.

Bob
This topic is locked and no more replies can be posted.