Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Issue with Content type using <cfform> or <form> and <cffile>

Guest
Jan 21, 2011 Jan 21, 2011

I'm receiving the below error whenever i attempt to upload a file.

Invalid content type: ''.

The cffile action="upload" requires forms to use enctype="multipart/form-data".

I'm using <cfform> and have the enctype="Multipart/form-data".

If i do not have a enctype ColdFusion states that the default enctype is incorrect.

I tried using <form> but experienced the same issue.

My <cfform> is in an include and is as follows:                    

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

      <cfform enctype="multipart/form-data" name="qb_email" action="OA_util_rpt3.cfm?List=#url.list#&t=#url.t#" method="POST" onsubmit="return FormCheck(this)">

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

My cffile is also in the same include where i have checks to make sure everything is entered correctly and a different path for the file uploading:
----------------
       <cffile action="upload" filefield="Attachments" destination="#TRIM(batch_dir)#"  nameconflict="overwrite">
----------------
Destination is present and starts with C:
Attachments is present.

Anyone have any ideas as to why i'm getting this error when i do in fact have enctype defined. I have this exact same code in several other pages and everywhere else it works fine. However, this is the only one where i go from a folder back to main directory, then to another folder for the include, and then back to main directory and then to batch to upload file.

Another interesting thing is the file is uploaded into my Batch folder but i get the message, and if i go back to the page, the file is listed and will be attached to my email as intended.

Thanks,

Daniel

1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 21, 2011 Jan 21, 2011

What's happening in the form's onsubmit event handler?

Dave Watts, CTO, Fig Leaf Software

http://www.figleaf.com/

http://training.figleaf.com/

Dave Watts, Eidolon LLC
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 21, 2011 Jan 21, 2011

I removed the onsubmit and still have the same issue.

What this is doing is sending an email and if i don't attach a file it works fine. It only happens when attaching a file.

Thanks For looking into this...

Daniel

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 21, 2011 Jan 21, 2011

Maybe you should post the form and action page(s) in their entirety.

Dave Watts, CTO, Fig Leaf Software

http://www.figleaf.com/

http://training.figleaf.com/

Dave Watts, Eidolon LLC
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 21, 2011 Jan 21, 2011

Like Dave, I suspect it's got to do with the onSubmit. It seems that the Javascript call changes the enctype to a blank. What if you do something like this

onsubmit="return FormCheck(this); return true;"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 21, 2011 Jan 21, 2011

Rough code for for <cfform> i removed the onsubmit and the issue still exists.

-----------

<cfform enctype="multipart/form-data" name="qb_email" action="OA_util_rpt3.cfm?List=#url.list#&t=#url.t#" method="POST">

<cfinput type="text" name="Subject" size="35" value='' required="yes" message="Please enter a subject.">
  <CFTEXTAREA height="300" richtext="yes" name="msg" required="yes" message="Please enter a message."> </cftextarea>
<input type="file" name="Attachments" size="40"><input type="Submit" name="attach" value="Attach File">
<input type="Submit" name="Submit" value=" Send ">
</cfform>
-----------
rough code for <cffile>
-----------
<cffile action="upload" filefield="Attachments" destination="#TRIM(batch_dir)#"  nameconflict="overwrite">
-----------
This is all in the same include with conditions to check whether the user has enter in data in the form and everything else. All the code works fine except when attempting to use <cffile> i have used <cfform> and <form> with and without onsubmit and received the same error message. The file does upload to the Batch_dir location however, there is the error so the page crashes. When i reload the page, the file is 'attached' and uploaded and when i send the email everything arrives.

I'm attempting to write an email include that will allow me to plug in this email with attachments anywhere i want. I have this exact same code. In about 10 different places and all of them work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 21, 2011 Jan 21, 2011

Try commenting out the CFTEXTAREA, or setting the RICHTEXT attribute to "no".

Dave Watts, CTO, Fig Leaf Software

http://www.figleaf.com/

http://training.figleaf.com/

Dave Watts, Eidolon LLC
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 21, 2011 Jan 21, 2011

Also, what exactly are you doing with the two submit buttons? That might be the cause of the problem. You should post your action page logic in full, not just the CFFILE tag, as I suggested earli

Dave Watts, CTO, Fig Leaf Software

http://www.figleaf.com/

http://training.figleaf.com/

Dave Watts, Eidolon LLC
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 21, 2011 Jan 21, 2011

Tthe 2 submits is for submitting the form for sending the email, and the other submit so submitting the form and attaching the files. This code was written before the uploadall in CF9. So we had to upload 1 file at a time.

The issue is only when i attach a file, and only with the cffile and for some reason enctype is being lost or set to ''. Does anyone know why a form would lose enctype? As i mentioned before, this code is working in about10 other places. So 2 submit buttons or other code i'm sure is not the issue. Is there a way where i can set content type after the forum that <cffile> will interpret?

Thanks for all your help,

Daniel

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 21, 2011 Jan 21, 2011

Again, unless you actually post all the code, all anyone can do is guess. Even then, it might be all we can do.

Dave Watts, CTO, Fig Leaf Software

http://www.figleaf.com/

http://training.figleaf.com/

Dave Watts, Eidolon LLC
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 21, 2011 Jan 21, 2011
<cfif isdefined("form.msg")>
                        <cfset session.msg = '#form.msg#'>
                    </cfif>
                    <cfif isdefined("form.signature_file")>
                        <cfset session.signature_file = '#form.signature_file#'>
                    </cfif>
                    <cfif isdefined("form.printed_name")>
                        <cfset session.printed_name = '#form.printed_name#'>
                    </cfif>
                    <cfif isdefined("form.Subject")>
                        <cfif ltrim(rtrim(#form.subject#)) EQ ''>
                            <cfset m = 'Please enter a subject.'>      
                            <cfoutput><cflocation url='#ListLast(cgi.SCRIPT_NAME,"/")#?List=#url.list#&t=#url.t#&m=#m#' addtoken="No"></cfoutput>
                        <cfelse>
                            <cfset session.Subject = '#form.Subject#'>
                        </cfif>
                    </cfif>
                 
                    <cfif isdefined('form.attach')>                  
                        <cfif #LEN(TRIM(form.Attachments))# eq 0>
                            <cfset m = 'Please select a file to attach or click Send.'>
                            <cflocation url='#returnpage#?list=#url.list#&t=#url.t#&m=#m#' addtoken="No">
                        </cfif>
                        <!--- Upload the file --->
                     
                     
                       <cffile action="upload" filefield="Attachments" destination="#TRIM(webopt.batch_dir)#"  nameconflict="overwrite">
                                                
<cfif #file.filewassaved#>
                            <Cfset file_ = "#file.ServerDirectory#\#file.serverfile#">
                            <cfset session.Attachments = '#ListAppend(session.Attachments, file_ , ";")#'>
                        </cfif>                    
                        <cftry>
                            <cfcatch>
                                <cflocation url='#ListLast(cgi.SCRIPT_NAME,"/")#?List=#url.list#&t=#url.t#&m=7100' addtoken="No">
                            </cfcatch>
                        </cftry>
                        <cflocation url='#ListLast(cgi.SCRIPT_NAME,"/")#?List=#url.list#&t=#url.t#' addtoken="No">               
                    </cfif>                 
                    <table cellpadding=0 cellspacing=0 border="0" width="100%"  bgcolor="#LTRIM(RTRIM(qry_webPage.bgcolor))#">
                        <tr>
                            <td colspan="6">
                                <CFINCLUDE template="dsp_PageName.cfm">
                            </td>
                        </tr>
                        <tr><td colspan="6"> </td></tr>
                        <tr>
                            <td colspan="6">
                                <table width="100%" border="0" cellpadding=0 cellspacing=0>
                                    <TR>
                                        <CFSET c = 'ref_name'>
                                        <CFINCLUDE template="qry_column.cfm">
                                        <td><CFINCLUDE template="dsp_Name.cfm"></td>
                                        <CFSET c = 'soc_sec'>
                                        <CFINCLUDE template="qry_column.cfm">
                                        <td><CFINCLUDE template="dsp_Name.cfm"></td>
                                        <CFSET c = 'e_mail'>
                                        <CFINCLUDE template="qry_column.cfm">
                                        <td><CFINCLUDE template="dsp_Name.cfm"></td>
                                        <TD><strong>Status</strong></td>
                                    </TR>
                                    <CFQUERY BLOCKFACTOR="100" NAME="qry_email" datasource="#sonis.ds#" dbtype="ODBC">
                                       gets data
                                    </cfquery>
                                    <cfset CC = '#session.operator_email#'>                 
                                    <!--- get path to signature file --->
                                    <cfif isdefined("session.signature_file") AND #ltrim(rtrim(session.signature_file))# NEQ ''>
                                        <cfset signature_file = #ltrim(rtrim(session.signature_file))#>
                                        <CFSET root= ExpandPath("../*.*")>
                                        <CFSET rootDir = GetDirectoryFromPath(root)>
                                        <CFSET thispath= ExpandPath("*.*")>
                                        <CFSET thisDir = GetDirectoryFromPath(thispath)>
                                        <cfset newDir = #thisDir#&'Images\signatures\'>
                                        <cfset sigfilepath =  #newDir#&#signature_file#>
                                        <cfif not FileExists(sigfilepath)>
                                           <cfset sigfilepath =  #newDir#&"nosigfile.gif">
                                        </cfif>
                                    </cfif>                 
                                    <!--- get value from fifth position of CF version --->
                                    <cfset CFVersion_extended = MID(SERVER.ColdFusion.ProductVersion,5,1) />                     
                                    <cfloop query="qry_email">
                                        <cftry>
                                            <cfif '#rtrim(qry_email.e_mail)#' EQ "?" OR '#rtrim(qry_email.e_mail)#' EQ ''>
                                                <cfthrow>
                                            </cfif>                 
                                            <!---<cfabort>--->
                                            <cfmail to="#e_mail#" from="#session.operator_email#" cc="#CC#"
                                                subject="#session.Subject#" type = "html">
                                               <cfloop index="attachments_lst_I" list="#session.Attachments#" delimiters=";">
                                                    <cfif (#CFVersion# EQ 8 AND #CFVersion_extended# GTE 1) OR #CFVersion# GT 8>
                                                 
                                                        <!---<CFSET thisDir = '#Listfirst(PATH_INFO,'/')#'>
                                                        <cfset newDir = #thisDir#&'/batch/'&'#ListLast(attachments_lst_I,'\')#'>
                                                        <cfmailparam file="#newDir#">
                                                        <cfinclude template="CFMAILPARAM_2.cfm">--->
                                                     
                                                        <cfif #listlen(session.Attachments,",")# eq 1>
                                                            <cfmailparam file="#attachments_lst_I#">
                                                        <cfelse>
                                                            <cfinclude template="CFMAILPARAM_2.cfm">
                                                        </cfif>
                                                    <cfelse>
                                               
                                                        <cfmailparam file="#attachments_lst_I#">
                                                        <!---<CFSET thisDir = '#Listfirst(PATH_INFO,'/')#'>
                                                        <cfset newDir = #thisDir#&'/batch/'&'#ListLast(attachments_lst_I,'\')#'>
                                                        <cfmailparam file="#newDir#">--->
                                                    </cfif>                    
                                                </cfloop>
                                                    #ltrim(rtrim(session.msg))#
                                                <cfif isdefined("session.signature_file") AND #rtrim(session.signature_file)# NEQ ''>
                                                    <p></p>
                                                    <cfmailparam file="#sigfilepath#"
                                                        disposition="inline"
                                                        contentID="image1">
                                                    <img src="cid:image1" height="42" width="160">
                                                </cfif>
                                                <cfif isdefined("session.printed_name") AND #rtrim(session.printed_name)# NEQ ''>
                                                    <p>#rtrim(session.printed_name)#</p>
                                                </cfif>
                                             
                                            </cfmail>
                                            <TR <cfif (CurrentRow MOD 2) eq 0>
                                                        bgcolor="#LTRIM(RTRIM(qry_webPage.bgcolor))#"
                                                    <cfelse>
                                                        bgcolor="#client.sepcolor#"
                                                    </cfif>>
                                                <td>#last_name#, #first_name#</td>
                                                <td>#soc_sec#</TD>
                                                <td>#e_mail#</TD>
                                                <TD>Email Sent.</td>
                                            </TR>
                                            <cfcatch>
                                                <TR>
                                                    <td>#last_name#, #first_name#</td>
                                                    <td>#soc_sec#</TD>
                                                    <td>#e_mail#</TD>
                                                    <TD><font color="Red"><strong>Email Failed.</strong></font></td>
                                                </TR>
                                            </cfcatch>
                                        </cftry>
                                        <cfset CC = ''>
                                    </cfloop>
                                    <CFSET DELETED = StructDelete(session, "signature_file")>
                                    <CFSET DELETED = StructDelete(session, "printed_name")>
                                    <CFSET DELETED = StructDelete(session, "subject")>
                                    <CFSET DELETED = StructDelete(session, "operator_email")>
                                    <CFSET DELETED = StructDelete(session, "attachments")>
                                    <CFSET DELETED = StructDelete(session, "msg")>
                                    <tr><td> </td></tr>
                                    <tr>
                                        <td colspan="6" align="center">
                                            <strong><a href='#returnPage#?list=#url.list#&t=#url.t#'>Return start page.</a></strong>
                                        </td>
                                    </tr>
                                    <tr><td> </td></tr>
                                </table>
                            </td>
                        </tr>
                        <CFINCLUDE template="dsp_message2.cfm">
                        </table>
all includes and variables are working correctly... so we can rule them out.... email sends so we can rule out <cfmail> and if there is attachments they are included in email so we can rule out that. Problem is when uploading the file that is the line the break happens.<cffile>
I can remove coding if need.
Thanks,

Daniel
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2011 Jan 22, 2011
LATEST

I thought you would be showing us the form page, not the action page. It would also help to show the stack trace or to indicate the line where the error occurs.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources