Skip to main content
April 10, 2008
Question

3-Function Action Page

  • April 10, 2008
  • 9 replies
  • 734 views
Greetings
I am having an issue with a form submission action page- I can get it to send the field contents to an email, and capture in a DB with the same action page- but when an file is chosen to upload, it fails.

I need to have cfinsert, cfmail to, and cffile action = "upload" on the same action page. The submitter may or may not upload a file with the submission, so I tried <cfif isDefined("Form.FileContents") > upload the file</cfif>, then insert in DB, then send the email.

Any help would be appreciated- Thanks

newportri
This topic has been closed for replies.

9 replies

April 11, 2008
Actaully they shouldn't make any difference, but the sequence I wrote is my preference. Also, make sure to use cftry and cfcatch for each process ...
April 11, 2008
Thanks to all who responded - I found the solution-

Sequence-

1) Data capture

2) Mail to

3) <cfif #Form.FileContents# IS "">
<cfabort>
<cfelse>
<cffile action = "upload"
filefield = "FileContents"
destination = "c:\whatever"
accept = "image/jpg,image/jpeg,image/pjpeg,image/gif,text/anytext,application/octet-stream"
nameConflict = "MakeUnique"> </cfif>


Thanks!
April 11, 2008
Greetings

Thanks- When the data capture is first, it looks for the form input name ,

ERROR=

"The FILECONTENTS fieldname cannot be found in the main table."

This is not a named field in the DB- I'm simply storing the file in a directory.

When the file manipulation is first with no file attached with the submitted form,

ERROR=

The form field FileContents did not contain a file.


Thanks again

newportri
April 11, 2008
Probably you've already tried changing the order of processing:
a) data capture;
b) file manipulation;
c) email
April 11, 2008
Yes:

<form action="request_support_action.cfm" method="post" enctype="multipart/form-data">


Thanks-

newportri
April 10, 2008

How's your FORM written? Did you have the enctype="multipart/form-data" Attribute?

Inspiring
April 10, 2008
Dumping variables is a debugging technique. Once you have solved the problem, you take out the dump tags.
April 10, 2008
Thanks for your quick response- It may be easier to show the code on the action page, then you can suggest a fix because I don't know why I'd dump the variables?

The Submitter is not required to upload a file with their submission (They may or may not).

ACTION PAGE:

<cfif isDefined("Form.FileContents") >
<cffile action = "upload"
filefield = "FileContents"
destination = "c:\Inetpub\wwwroot\whatever\"
accept = "image/jpg,image/jpeg,image/pjpeg,image/gif,text/anytext,application/octet-stream"
nameConflict = "MakeUnique"> </cfif>



<cfinsert datasource="whatever" tablename="whatever">


<cfmail to="whatever@whatever.com"
from="#Form.request_email#"
subject="whatever"
server ="whatever">


The following is the result of a Form Submission:

Date: #dte_received#
Time: #tme_received#

ETC.
</cfmail>

<html>
<head>
<title> Form Submission</title>
</head

<body>
<h3>Thank You For Your Submission</h3>
</body>
</html>

Thanks...

newportri
Inspiring
April 10, 2008
cfdump is your freind.

submit your form without uploading a file. then do this

<cfdump var="#isDefined('Form.FileContents') "#>
<cfdump var="#Form.#">
<cfabort>