Advertisement

08.26.2008 at 11:03PM PDT, ID: 23681027 | Points: 500
[x]
Attachment Details

Uploading and deleting attachments within cfmail form

Asked by CurtinProp in Cold Fusion Markup Language

Tags: ,

I have an email form that requires attachments, can anyone give me a CF script that can add multiple attachments which display onscreen:

 for example:

* a User would browse for a file / select it / then click attach
* the user could then browse for another file / select it / then click attach

----------------------------------------------------

* The attached files would display on screen with the ability to remove unwanted attachments.

----------------------------------------------------

* Once the user has attached their files they then hit submit to send the form.

I have a script that works fine with the one attachment, but I'd like to get a bit more advanced than this..... please feel free to modify the code in the snippet (I'd actually prefer it that way, lets me see whats going on)

cheers

Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
<cfparam name="FORM.attachment_1" default="">
<cfparam name="FORM.subject" default="">
<cfparam name="FORM.message" default="">
<cfparam name="FORM.name" default="">
 
<!--- check for upload --->
 
<cfif FORM.attachment_1 neq "">
 
   <!--- upload file --->
   
   <cffile action="upload"
             filefield="attachment_1"
             destination="/web/wprop/web/forms/uploads/attach"
             nameconflict="Makeunique">
             
    <!--- temp folder on server --->
    
    <cfset attachment_local_file_1 = "/web/wprop/web/forms/uploads/attach/#file.serverfile#">
</cfif>
 
 
 
<!--- email with attachments --->
 
 
 
<cfmail from="EMAIL ADDRESS" to="EMAIL ADDRESS" subject="#subject#">
    #message# #name#
    
       <cfsilent>
   
     <!--- cfsilent (to kill whitespace) --->
     
     <cfif FORM.attachment_1 neq "">
        <cfmailparam file="#attachment_local_file_1#">
     </cfif>
   </cfsilent>
 
</cfmail>
 
 <!--- <cffile action = "delete" file ="/web/wprop/web/forms/uploads/attach/#attachment_local_file_1#"> --->
 
 
         <form action="mail_form.cfm" method="post" enctype="multipart/form-data">
          <table width="500" border="0" align="center">
              <tr>
                  <td width="500" colspan="2">Please enter your email message:</td>
              </tr>
              <tr>
                  <td width="250">Name:</td>
                  <td width="250"><input type="text" name="name" value=""></td>
              </tr>
              <tr>
                  <td width="250">Subject:</td>
                  <td width="250"><input type="text" name="subject" value=""></td>
              </tr>
              <tr>
                  <td width="250" valign="top">Message</td>
                  <td width="250"><textarea name="message" rows="5" cols="35"></textarea></td>
              </tr>
              <tr>
                  <td width="250">Attachment #1:</td>
                  <td width="250"><input type="file" name="attachment_1" value=""></td>
              </tr>
              <tr>
                  <td width="250">&nbsp;</td>
                  <td width="250"><input type="submit" name="Send_ Email" value="Send Email"></td>
              </tr>
          </table>
         </form>
 
 
Loading Advertisement...
 
[+][-]09.16.2008 at 11:34AM PDT, ID: 22491698

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628