Copy link to clipboard
Copied
this has been posted before - but without an "answer" - simply an "ugly" woraround...
http://forums.adobe.com/message/2774350
I am having the SAME issue - and would really like an answer as to why or what is needed in order to make the cfwindow and built in ajax handle a the cfforms attributes correctly...
this issue is trying to upload Images through a cffile in a CFWINDOW and I keep getting the below error
"Invalid content type: application/x-www-form-urlencoded; charset=UTF-8"
"The cffile action="upload" requires forms to use enctype="multipart/form-data".
The cfform file is already set to "enctype="multipart/form-data".
CODE calling the window
==== BEGIN PAGE ====
<html>
<head>
<script>
function launchWin(name,url) {
ColdFusion.Window.create(name+'_formWindow', name, url,
{ height:500,
width:500,
modal:true,
closable:true,
draggable:true,
resizable:true,
center:true,
initshow:true,
minheight:200,
minwidth:200
})
}
</script>
</head>
<body>
<cfdiv id="myContent">
<a href="javascript:launchWin( 'Attachment', 'attachment.cfm?' );" >ATTACHMENT</a>
<!--- other code blah blah --->
</cfdiv>
</body>
</html>
==== END PAGE ====
Here is the simple code... for the file INSIDE the cfwindow
==== BEGIN PAGE ====
<script>
ColdFusion.Window.onHide( 'Attachment_formWindow', cleanup );
function cleanup() {
ColdFusion.Window.destroy( 'Attachment_formWindow', true );
}
</script>
<!--- HANDLE THE FORM --->
<cfif structKeyExists( FORM, 'add_Attachment' ) >
<!--- Do CFFILE to handle file upload --->
<cffile action="upload"
destination="C:\"
filefield="theFile"
nameconflict="makeunique">
<!--- refresh the calling page, and close this window - destroy it so contents don't presist --->
<script>
ColdFusion.navigate( 'page.cfm?', 'myContent' );
ColdFusion.Window.hide( 'Attachment_formWindow' );
</script>
</cfif>
<!--- form to get information --->
<cfform name="attachmentForm" enctype="multipart/form-data" >
<table>
<tr><td>FILE:</td><td><cfinput type="file" name="theFile" size="40" /></td></tr>
<tr><td>TITLE:</td><td><cfinput type="text" name="name" value="" size="40" maxlength="100" /></td></tr>
<tr><td>DESCRIPTION:</td><td><cftextarea name="description" cols="40" rows="10"></cftextarea></td></tr>
<tr><td></td><td><cfinput type="submit" name="add_Attachment" value="Add" /></td></tr>
</table>
</cfform>
==== END PAGE ====
Copy link to clipboard
Copied
As I understand it, that is not an "ugly" workaround. It is the ONLY work around. And it's not a problem with making "cfwindow and built in ajax handle a the cfforms attributes correctly", you cannot upload a file via XHR. Every Ajax upload solution I have ever seen requires the use of iframes. An Ajax XHR cannot have the appropriate enctype for file uploads.
When you place a cfform in a cfwindow it no longer submits normally, ColdFusion changes it to a Ajax submit process (by design). If you don't want it to work that way, then use the iframe solution.
Jason
Copy link to clipboard
Copied
thank you for your answer Jason. The form - at least submits...
Now i must find a suitable way to close my window upon submitting - simply moving the code into the iFrame does not sem to handle that.
The "ugliness" I'm referring to (and this ISN'T directed at you - I appreciate your answer) is the fact that one is FORCED to use iframes and, in so doing, I must call an iframe page that calls it's source page...
bloating my code base by one page for every form that may have an element that AJAX (or where ever thh root cause is) cannot handle.
for instance - i have a little application that uses windows for collecting all information (seems simple enough) - out of a dozen forms - I have 3 that use either 'file upload' or a wsywig editor that requires iframes ... the site design is simple and efficient. the logic is well lait out - but NOW (even though file input has been around forever) I have to blaot my code - and obfuscate the 'real' form template thru the iframe... it's ugly.
sorry - i'm ranting - because I spent considerable time getting rid of bloat and unnecesary code nesting - now I have to either 'allow' this anomoly on forms that require it - OR I have to do it for ALL forms - so the architecture is consistent across each window request...