Forums

[Re-opened] Emailing Attachments

chrisdavies71 18 Sep, 2012
Hi,

I am trying to build a Document Library with the ability to email.

I have created a form with checkboxes.

What I need to do is relate each checkbox to an individual file so that if a user checks boxes 1 & 2 they are emailed files 1&2 (for example) but if the user checks boxes 3 & 7 they are sent files 3&7.

Is this possible?

Many Thanks

CHRIS
GreyHead 24 Sep, 2012
Hi Chris,

If you use my custom Email [GH] action you can specify a 'static' file, or a comma separated list of files to be attached. If you use a Custom Code action to build a list this should do what you need.

Bob
chrisdavies71 22 Oct, 2012
Hi,

Thanks for the Custom Email action - how do i use the custom code action to build the list of files to be attached? At the moment I am having to create a new email action for each file which then send multiple emails if the user selects multiple checkboxes. Ideally they should receive just one email with all the files attached.

CHRIS
GreyHead 22 Oct, 2012
Hi Chris,

It will be something like this:
<?php
$form->data['attach_files'] = '';
if ( !isset($form->data['checkboxes']) || count($form->data['checkboxes']) == 0 ) {
  return;
}
$files_array = array (
  1 => 'some_path/some_file.pdf',
  2 => '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['attach_files'] = implode(',', $attach_files);
?>

Bob
chrisdavies71 22 Oct, 2012
Hi Bob,

Thanks for the code - I am no coder but i get the basic logic there.

How do i then associate the array/list that this code creates to the email action and do i still need the condition field of the email action filled in?

Would you be able to do the work for me (for a fee of course!!) if i give you access to the site? - just thinking is may be less painful for you.

Cheers

CHRIS
GreyHead 22 Oct, 2012
Hi Chris,

How do i then associate the array/list that this code creates to the email action and do i still need the condition field of the email action filled in?


Sorry, I forgot that bit. Add {attach_files} to the Attachments box in the Email [GH] action

Would you be able to do the work for me (for a fee of course!!) if i give you access to the site? - just thinking is may be less painful for you.

Happy to have a look but I suggest that you have a go yourself first - that may be easier than specifying exactly what you need for me to do it. Email or PM me if you need more help.

Bob
GreyHead 22 Oct, 2012
Hi Chris,

It looks as though my Email [GH] action doesn't quite work the way I thought it did. It won't accept a list of file paths in quite that way. I'll see if I can adapt the code and update it.

I changed a few other things on your site.

a) I gave the first two checkboxes array names checkboxes[] and unique default values 1, 2, etc. I also turned off the 'Ghost' settings. This gives all the checkbox results in a neat single array.

b) I replaced the file URL you added to the custom code with the file path which is reauired for attachements

c) I fixed a typo in my sample code (now fixed in my earlier post here).

At the end of all that we have a comma separated list being correctly created.

Bob
chrisdavies71 22 Oct, 2012
Hi Bob,

Thanks for that - look forward to the updated Email Action.

I will make a start on the thumbnail images and adding all the checkboxes as needed then we can look at finishing off when the update is available.

Many Thanks

CHRIS
GreyHead 22 Oct, 2012
Hi Chris,

It should be working OK now.

Bob
chrisdavies71 29 Oct, 2012
Hi Bob,

Thank you, Thank you so much you are a star!! - works exactly as i wanted.

I have added a "DB Save" action to the "On Submit" event so that i can collect the name and email address of people using the service. I have created the link to the table etc and it creates a record each time i use the form but it doesn't store the name and email address fields - any thoughts?

Is it also possible to get the "DB Save" action to store the title of the downloads that people make in each record?

Beer being bought now.

CHRIS
GreyHead 29 Oct, 2012
Hi Chris,

It should save any fields from the form OK provided that the input name and column name match.

Please drag a Debugger action into the On Submit event, then submit the form and post the debug results here.

Similarly it will save the uploaded file names but you may need to add a Handle Arrays action to convert the file name array into a string.

Bob
chrisdavies71 29 Oct, 2012
Hi Bob,

Thanks for that, works as expected.

Quick question: currently when viewing the "DB Save" table/results the checkbox value is 1,2,3 dependant on which document was requested. In order to make this the name of the file - Application Form for example would i simply change the numerical value in the $files_array and on the checkboxes[] field id in the checkbox element as well?

Hope that make sense, I have copied the array here for reference:

<?php
if ( !isset($form->data['checkboxes']) || count($form->data['checkboxes']) == 0 ) {
  return;
}
$files_array = array (
  "1" => JPATH_SITE.'/documents/Application Form.pdf',
  "2" => JPATH_SITE.'/documents/BBC Application Form.pdf',
  "3" => JPATH_SITE.'/documents/New Entrants Application Form.pdf',
  "4" => JPATH_SITE.'/documents/files/joomla_green.gif',
  "5" => JPATH_SITE.'/documents/files/joomla_green.gif',
  "6" => JPATH_SITE.'/documents/files/joomla_green.gif',
  "7" => JPATH_SITE.'/documents/files/joomla_green.gif',
  "8" => JPATH_SITE.'/documents/files/joomla_green.gif',
  "9" => JPATH_SITE.'/documents/files/joomla_green.gif',
);
$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;
?> 


Many Thanks

CHRIS
GreyHead 30 Oct, 2012
Hi Chris,

In theory you could change the checkbox values to be the file names. In practice my experience is that that can be messy :-(

Better to leave the checkbox values with shortcodes: numbers are OK but you could also use short mnemonics like 'abc', or 'product_14', or 'green_logo'.

This may be enough, otherwise you can extend the code use to look up the file paths and add a version that gets the names as well and puts them into an array or string to save in the database.

Bob
Joomlimo 02 Nov, 2012
I have the same problem, and although I made sure the field name matches in both the field and the email action configurations, the problem still persists and nothing gets attached to the email message.

I grabbed the debugger, and here is the results:

Data Array:

(
    [option] => com_chronoforms
    [tmpl] => component
    [chronoform] => article_contribution
    [event] => submit
    [Itemid] => 
    [name] => John Smith
    [email] => name@domain.com
    [title] => Demo
    [article_text] => Demo text
    [main_pic] => 
    [img_2] => 
    [img_3] => 
    [img_4] => 
    [Submit] => Submit
    [827d699042c9ea4c08f11c47715ac0bf] => 1
    [_PLUGINS_] => Array
        (
            [upload_files] => Array
                (
                )

        )

)


 Debug Data

    email
        10
            Result An email has been SENT successfully from (John Smith)name@domain.com to test@gmail.com
            Body
            Name 	John Smith
            E-mail 	name@domain.com
            Title 	Demo
            Text 	Demo text
            Main image 	
            Image 2 	
            Image 3 	
            Image 4	
            Attachments array ( )



Notice that Main image, whose associated field, "main_pic", appears to have no value is the field where I attached my file.

Thanks
GreyHead 04 Nov, 2012
Hi joomlimo,

The Upload Files action isn't copying the files over from the PHP temp folder. This is probably because the action isn't recognising the entry in the File types box.

Bob
Joomlimo 05 Nov, 2012
Yeah, I designated the filetypes in the proper format, and that solved it!

Thanks, Greyhead.
chrisdavies71 12 Jun, 2013
Hi Bob,

Hope you are well?

I have updated the site to Joomla 3 and been going through bits - it seems that the code is no longer working. I am using your updated Email [GH] Action. I am getting the checkbox to correspond to the various files i am just not getting those files attached to the email.

Below is what i get in the Debugger:

Data Array: 
Array
(
    [option] => com_chronoforms
    [tmpl] => component
    [chronoform] => Docs2
    [event] => submit
    [cf_sid] => e032054372c6897b5377ec0c7b3b819f
    [name] => Chris
    [email_address] => chrisdavies71@me.com
    [input_submit_29] => Submit
    [83d6bbb2bc51c2b2a7173d8b104e7b3c] => 1
    [checkboxes] => 1,2
    [input_submit_31] => Next: Enter your Details
    [file_array] => /home/bectuym/public_html/tradeshow/documents/Application Form.pdf,/home/bectuym/public_html/tradeshow/documents/BBC Application Form.pdf
    [IPADDRESS] => 81.155.166.44
)
Validation Errors: 
Array
(
)
Thanks for using the BECTU Documents Library. Your documents will be email to you shortly.

Debug Data
Email info
Email sent successfully
From: (BECTU) info@bectuym.net
To: chrisdavies71@me.com
Subject: Your BECTU Documents
Email body
Hi Chris,

Thank you for requesting documents from BECTU. The files you requested are attached to this email.

BECTU

www.bectu.org.uk

Any Thoughts?

Cheers

CHRIS
GreyHead 05 Sep, 2013
Hi Chrisdavies71,

Did this get solved? I've just got back to some very old tabs and see that I didn't reply. I would expect this to work if you have {file_array} in the Email [GH] action attachments box and the Email [GH] action is after the Custom Code action where you set the files.

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