Form not working?

Coldfusion form not working.

Page 1 of 1

1 Replies - 2037 Views - Last Post: 15 February 2008 - 07:36 PM Rate Topic: -----

#1 parenteau  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 12-February 08

Form not working?

Posted 13 February 2008 - 08:02 PM

I don't know why this isn't working...
and cant figure out how to redirect the page.
I am new at this and am really interested in developing what I design... but have run into some language barriers.
here is the code... I feel like I am losing my mind!!! I figured someone could look at this and figure out what I am missing.

<form action="test.cfm" method="post" enctype="multipart/form-data"><cfif structKeyExists(form, "uploadfile")>
<cfset destination = expandPath("./files")>
<cfif not directoryExists(destination)>
<cfdirectory action="create" directory="#destination#">
</cfif>

<cffile action="upload" filefield="uploadfile" destination="#destination#" nameConflict="makeUnique" result="upload">
<cfdump var="#upload#">
</cfif>
	  <div align="center"><table width="500" border="0" align="center" cellpadding="7">
		<tr>
		  <td width="100%" bgcolor="#EEF1F7"><p align="center"><b><font face="Tahoma" size="2">Please make sure that the files you are uploading do <br />
			not have the same name as other files you have uploaded!</font></b> </p></td>
		</tr>
		<tr>
		  <td width="100%" bgcolor="#E1E6F0"><p align="center"><b><font face="Tahoma" size="2">Upload
			Options</font></b></p></td>
		</tr>
		<tr>
		  <td width="100%" bgcolor="#EEF1F7"><table border="0" width="100%" cellpadding="4">
			  <tr>
				<td width="34%" align="right" bgcolor="#E1E6F0" valign="top"><font face="Tahoma" size="2"><b>Select
				File To Upload:</b></font></td>
				<td width="66%" bgcolor="#EAEDF4"><p>
				  <input type="file" name="uploadfile" />
				  <br />
					<br />
					<input type="submit" value="Upload File" />



Is This A Good Question/Topic? 0
  • +

Replies To: Form not working?

#2 sansclue  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 316
  • Joined: 21-November 07

Re: Form not working?

Posted 15 February 2008 - 07:36 PM

I just noticed the location of your upload tag. Everything else looks good. I think you just need to move your <cffile> upload inside the <cfif> statement. So the code only does the upload after the form is submitted.


<cfif structKeyExists(form, "uploadfile")>
	<cfset destination = expandPath("./files")>
	<cfif not directoryExists(destination)>
		 <cfdirectory action="create" directory="#destination#">
		</cfif>
		   
	   <cffile action="upload" filefield="uploadfile" destination="#destination#" 
		   nameConflict="makeUnique" result="upload">
	   <cfdump var="#upload#">

</cfif>



The code should work either way, but IMO it's cleaner to place the upload code before the <form> tags, not inside them.

This post has been edited by sansclue: 15 February 2008 - 07:45 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1