Martyn9098
asked on
Coldfusion enctype multipart/form-data cannot access other form data
Hi,
I have created a form using the <cfform> tag and because part of my form requires a file upload I have set the enctype to multipart/form-data however when doing this the file is uploaded but I cannot access any of the other form fields data. If I remove the enctype I cannot upload the file but I can access the other form field data.
Any ideas ?
Thanks
Martyn
I have created a form using the <cfform> tag and because part of my form requires a file upload I have set the enctype to multipart/form-data however when doing this the file is uploaded but I cannot access any of the other form fields data. If I remove the enctype I cannot upload the file but I can access the other form field data.
Any ideas ?
Thanks
Martyn
Is there a URL where we can look at the form?
ASKER
Sadly no, it's an internal admin portal i'm creating. The company would not allow me to show / post etc. I think this maybe my downfall.
Martyn
Martyn
Just ran that scenario on my server and it's working as intended. Without being able to see your code, I can't really help diagnose your issue. :/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Rodrigo, I think that helps prove it's an issue with my code.
Form code below if you can help ? I have no other option but to post it.
thanks
Martyn
<cfform action="addadvert.cfm" method="post" enctype="multipart/form-da ta" id="form" name="form">
<tr>
<td width="150" class="formdata" align="right"> Compan y Name</td>
<td width="448" colspan="2">
<cfinput alt="Company Name" size="60" id="cname" maxlength="100" name="cname" tabindex="1" type="text" value="" /></td>
</tr>
<tr>
<td width="150" class="hintdata" align="right">(Max 50 chars) </td>
<td colspan="2" align="right" class="hintdata"> </t d>
</tr>
<tr>
<td colspan="3"><br /></td>
</tr>
<tr>
<td width="150" class="formdata" align="right" valign="top"> Website Address<br />
<span class="hintdata">(Max 255 chars) </span></td>
<td colspan="2">
<cfinput alt="Website Address" size="60" id="wurl" maxlength="255" name="wurl" tabindex="2" ></td>
</tr>
<tr>
<td colspan="3"><br /></td>
</tr>
<tr>
<td width="150" class="formdata" align="right"> Catego ry</td>
<td colspan="2">
<cfselect id="category" name="category"> <cfoutput query="bdcats">
<option value="#bdcats.name#">#bdc ats.name#< /option>
</cfoutput> </cfselect></td>
</tr>
<tr>
<td colspan="3"><br /></td>
</tr>
<tr>
<td width="150" class="formdata" align="right"> Advert Type</td>
<td colspan="2">
<cfselect tabindex="4" name="atype" id="atype">
<option value="Square">Square</opt ion>
<option value="Horizontal Rectangle">Horizontal Rectangle</option>
<option value="Vertical Rectangle">Vertical Rectangle</option>
</cfselect></td>
</tr>
<tr>
<tr>
<td colspan="3"><br /></td>
</tr>
<tr>
<td width="150" class="formdata" align="right" valign="top"> Advert Status<br /></td>
<td colspan="2">
<cfselect tabindex="5" name="status" id="status">
<option value="1">Live</option>
<option value="0">Dead</option>
</cfselect></td>
</tr>
<tr>
<td colspan="3"><br /></td>
</tr>
<tr>
<tr>
<td width="150" class="formdata" align="right" valign="top"> Upload Advert</td>
<td colspan="2">
<!---
Create folder structure or change to fit your needs
Expects images to be uploaded to images and thumbnails go in thumbs
--->
<!--- set the full path to the images folder --->
<cfset mediapath = expandpath('tmpimages')>
<!--- set the desired image height ---->
<cfset thumbsize = 164>
<!--- set the desired image width --->
<cfset imagesize = 164>
<cfif structKeyExists(form,"file Upload") and len(form.fileUpload)>
<cffile action="upload"
filefield="FileUpload"
destination="#MediaPath#"
nameconflict="makeunique">
<!--- read the image ---->
<cfimage name="uploadedImage"
source="#MediaPath#/#file. serverFile #" >
<!--- figure out which way to scale the image --->
<cfif uploadedImage.width gt uploadedImage.height>
<cfset thmb_percentage = (thumbsize / uploadedImage.width)>
<cfset percentage = (imagesize / uploadedImage.width)>
<cfelse>
<cfset thmb_percentage = (thumbsize / uploadedImage.height)>
<cfset percentage = (imagesize / uploadedImage.height)>
</cfif>
<!--- calculate the new thumbnail and image height/width --->
<cfset thumbWidth = round(uploadedImage.width * thmb_percentage)>
<cfset thumbHeight = round(uploadedImage.height * thmb_percentage)>
<cfset newWidth = round(uploadedImage.width * percentage)>
<cfset newHeight = round(uploadedImage.height * percentage)>
<!--- see if we need to resize the image, maybe it is already smaller than our desired size --->
<cfif uploadedImage.width gt imagesize>
<cfimage action="resize"
height="#newHeight#"
width="#newWidth#"
source="#uploadedImage#"
destination="#MediaPath#/# file.serve rFile#"
overwrite="true"/>
</cfif>
<!--- create a thumbnail for the image --->
<cfimage action="resize"
height="#thumbHeight#"
width="#thumbWidth#"
source="#uploadedImage#"
destination="../images/ads /#file.ser verFile#"
overwrite="true"/>
<cfoutput>
<cflocation url="addadvert.cfm">
<img src="../newsimages/thumbs/ #file.serv erFile#" height="#thumbHeight#" width="#thumbWidth#" align="left" hspace="10"><br>
Original Image: #uploadedImage.width#x#upl oadedImage .height#<b r>
Resized Image: #newWidth#x#newHeight#<br>
Thumbnail: #thumbWidth#x#thumbHeight# <br>
<br>
</cfoutput>
</cfif>
<cfinput type="file" name="fileUpload" id="fileUpload"></td>
</tr>
<tr>
<td colspan="3"><br /></td>
</tr>
<tr>
<td width="150" class="formdata" align="right"> Create d By</td>
<td colspan="2">
<cfinput alt="Created By" size="60" disabled="disabled" id="cby" maxlength="50" name="cby" tabindex="6" type="text" value="#session.realname#" /></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3"><cfinput type="hidden" name="add" id="add" value="add" />
<br /></td>
</tr>
<tr>
<td width="150" class="formdata" align="right"> </td>
<td colspan="2">
<cfinput name="Submit" type="submit" value="Submit" tabindex="6" />
<cfinput type="button" name="cancel" value="cancel" onClick="javascript:locati on.href='b dentry.cfm ';"></td>
</tr>
<tr>
<td colspan="3"><br /></td>
</tr>
</cfform>
Form code below if you can help ? I have no other option but to post it.
thanks
Martyn
<cfform action="addadvert.cfm" method="post" enctype="multipart/form-da
<tr>
<td width="150" class="formdata" align="right"> Compan
<td width="448" colspan="2">
<cfinput alt="Company Name" size="60" id="cname" maxlength="100" name="cname" tabindex="1" type="text" value="" /></td>
</tr>
<tr>
<td width="150" class="hintdata" align="right">(Max 50 chars) </td>
<td colspan="2" align="right" class="hintdata"> </t
</tr>
<tr>
<td colspan="3"><br /></td>
</tr>
<tr>
<td width="150" class="formdata" align="right" valign="top"> Website
<span class="hintdata">(Max 255 chars) </span></td>
<td colspan="2">
<cfinput alt="Website Address" size="60" id="wurl" maxlength="255" name="wurl" tabindex="2" ></td>
</tr>
<tr>
<td colspan="3"><br /></td>
</tr>
<tr>
<td width="150" class="formdata" align="right"> Catego
<td colspan="2">
<cfselect id="category" name="category"> <cfoutput query="bdcats">
<option value="#bdcats.name#">#bdc
</cfoutput> </cfselect></td>
</tr>
<tr>
<td colspan="3"><br /></td>
</tr>
<tr>
<td width="150" class="formdata" align="right"> Advert
<td colspan="2">
<cfselect tabindex="4" name="atype" id="atype">
<option value="Square">Square</opt
<option value="Horizontal Rectangle">Horizontal Rectangle</option>
<option value="Vertical Rectangle">Vertical Rectangle</option>
</cfselect></td>
</tr>
<tr>
<tr>
<td colspan="3"><br /></td>
</tr>
<tr>
<td width="150" class="formdata" align="right" valign="top"> Advert Status<br /></td>
<td colspan="2">
<cfselect tabindex="5" name="status" id="status">
<option value="1">Live</option>
<option value="0">Dead</option>
</cfselect></td>
</tr>
<tr>
<td colspan="3"><br /></td>
</tr>
<tr>
<tr>
<td width="150" class="formdata" align="right" valign="top"> Upload Advert</td>
<td colspan="2">
<!---
Create folder structure or change to fit your needs
Expects images to be uploaded to images and thumbnails go in thumbs
--->
<!--- set the full path to the images folder --->
<cfset mediapath = expandpath('tmpimages')>
<!--- set the desired image height ---->
<cfset thumbsize = 164>
<!--- set the desired image width --->
<cfset imagesize = 164>
<cfif structKeyExists(form,"file
<cffile action="upload"
filefield="FileUpload"
destination="#MediaPath#"
nameconflict="makeunique">
<!--- read the image ---->
<cfimage name="uploadedImage"
source="#MediaPath#/#file.
<!--- figure out which way to scale the image --->
<cfif uploadedImage.width gt uploadedImage.height>
<cfset thmb_percentage = (thumbsize / uploadedImage.width)>
<cfset percentage = (imagesize / uploadedImage.width)>
<cfelse>
<cfset thmb_percentage = (thumbsize / uploadedImage.height)>
<cfset percentage = (imagesize / uploadedImage.height)>
</cfif>
<!--- calculate the new thumbnail and image height/width --->
<cfset thumbWidth = round(uploadedImage.width * thmb_percentage)>
<cfset thumbHeight = round(uploadedImage.height
<cfset newWidth = round(uploadedImage.width * percentage)>
<cfset newHeight = round(uploadedImage.height
<!--- see if we need to resize the image, maybe it is already smaller than our desired size --->
<cfif uploadedImage.width gt imagesize>
<cfimage action="resize"
height="#newHeight#"
width="#newWidth#"
source="#uploadedImage#"
destination="#MediaPath#/#
overwrite="true"/>
</cfif>
<!--- create a thumbnail for the image --->
<cfimage action="resize"
height="#thumbHeight#"
width="#thumbWidth#"
source="#uploadedImage#"
destination="../images/ads
overwrite="true"/>
<cfoutput>
<cflocation url="addadvert.cfm">
<img src="../newsimages/thumbs/
Original Image: #uploadedImage.width#x#upl
Resized Image: #newWidth#x#newHeight#<br>
Thumbnail: #thumbWidth#x#thumbHeight#
<br>
</cfoutput>
</cfif>
<cfinput type="file" name="fileUpload" id="fileUpload"></td>
</tr>
<tr>
<td colspan="3"><br /></td>
</tr>
<tr>
<td width="150" class="formdata" align="right"> Create
<td colspan="2">
<cfinput alt="Created By" size="60" disabled="disabled" id="cby" maxlength="50" name="cby" tabindex="6" type="text" value="#session.realname#"
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3"><cfinput type="hidden" name="add" id="add" value="add" />
<br /></td>
</tr>
<tr>
<td width="150" class="formdata" align="right"> </td>
<td colspan="2">
<cfinput name="Submit" type="submit" value="Submit" tabindex="6" />
<cfinput type="button" name="cancel" value="cancel" onClick="javascript:locati
</tr>
<tr>
<td colspan="3"><br /></td>
</tr>
</cfform>
ASKER
If it helps, I get a
struct: [empty]
on the result of a cfdump var = form.
Thanks
struct: [empty]
on the result of a cfdump var = form.
Thanks
ASKER
The cfdump routine allowed me to investigate more to find the cflocation tag I left in there causing the form data to be lost.
Many thanks
Martyn
Many thanks
Martyn
Ah!! good to know! glad I could help :)