• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

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?

Thanks,
G
0
bodachs
Asked:
bodachs
  • 5
  • 2
1 Solution
 
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
0
 
James RodgersWeb Applications DeveloperCommented:
tested in ie and ff
<script language="JavaScript" type="text/javascript">
function validateExt(objFile){
      if(objFile.value){
            arrTemp=objFile.value.split('.');
            alert(arrTemp[arrTemp.length-1]);
      }

}

</script>
0
 
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
http://www.utoronto.ca/webdocs/HTMLdocs/Book/Book-3ed/appb/mimetype.html
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
bodachsAuthor Commented:
Jester,

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.

G
0
 
James RodgersWeb 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

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

</cfcatch>

</cftry>
0
 
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!!!!
G
0
 
James RodgersWeb Applications DeveloperCommented:
glad i could help

thanks for the points
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now