CFFILE Tag w/ Validation

Hello, I have just implemented a CFFILE tag which works fine as long as the pdf document is uploaded.  However, when someone attaches a doc or xls it still moves to the next page, but, it gives an error that the document is not the right type (pdf) all the way at the bottom of the page (hardly noticeable / understandable to many users).  

Is there a way before I submit the file or during the form action page a validation mechanism occurs that the file is NOT a pdf and throws an error on the first page saying that it's not a pdf, thus stopping the confusion?

Who is Participating?
James RodgersConnect With a Mentor Web Applications DeveloperCommented:
you might also use a <cftry><cfcatch> and catch the upload error and present your own user friendly error messages to the user

i would suggest that you NOT rely solely on the js solution but a combination of js and cf

<cffile action="upload" ...
<cfcatch type="Any">
custom error code or error flag goes here


James RodgersWeb Applications DeveloperCommented:
have you set the accept value in the cffile tag?
javascript can be used to vaslidate the file type prior to submission but it will probably not be cross browser compliant and will not really validate teh fiel but rather teh file extension
gimme a minute and i will get the code
James RodgersWeb Applications DeveloperCommented:
tested in ie and ff
<script language="JavaScript" type="text/javascript">
function validateExt(objFile){


Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

James RodgersWeb Applications DeveloperCommented:
and checking the mime type in cf
<cffile action="UPLOAD" destination="#expandPath('.')#" filefield="form.fileField" accept="application/pdf">
heres a list of mime types
bodachsAuthor Commented:

I did put the MIME type to application/pdf on the action page.  It still gives me the "ugly" cf error messages which make no sense to webusers who know nothing about it.  They just assume the site doesn't work.  

I will try your test script and let you know what I come up with.

bodachsAuthor Commented:
Jester the CFCATCH/CFTRY tags worked like a charm!!!!  Thanks so much, good work around for issues like this in the future.  

Thanks again for your help!!!!
James RodgersWeb Applications DeveloperCommented:
glad i could help

thanks for the points
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.