Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I get my form to submit if file upload field is left blank?

Posted on 2009-07-07
2
Medium Priority
?
214 Views
Last Modified: 2013-12-24
Hi folks, this is probably an easy one Im fairly new to CF.  I have a simple form for the user to fill out.  I added two file upload fields to the form that will store the file in a directory on the server and store the absolute path in the database.  Everything works fine when files are uploaded but when the user skips uploading a file the page will not go through. (This will not be a mandatory field) Im getting the error VARIABLE FULLFILEPATH IS UNDEFINED.

I added <cfif (form.agenda) NEQ ""> for the code to move on if there is no file to be uploaded but its getting hung up on <cfset FullFilePath="http://########item/#CFFILE.ServerFilename#.#CFFILE.ServerFileExt#">

I hope Im explaining this ok.  Any help would be appreciated.  

<cfif form.operation IS "Submit">
 
<cfset destination=GetDirectoryFromPath(CGI.PATH_TRANSLATED) & "docs\">
<cfif (form.agenda) NEQ "">
<cffile
	action="upload"
	filefield="agenda"
	destination=#destination#"
	nameconflict='makeunique">
 
<cfset FullFilePath="http://########docs/#CFFILE.ServerFilename#.#CFFILE.ServerFileExt#">
</cfif>
 
 
<cfset destination=GetDirectoryFromPath(CGI.PATH_TRANSLATED) & "item\">
<cfif (form.item) NEQ "">
<cffile
	action="upload"
	filefield="item"
	destination=#destination#"
	nameconflict='makeunique">
 
<cfset FullFilePath1="http://########item/#CFFILE.ServerFilename#.#CFFILE.ServerFileExt#">
</cfif>
 
	<cfquery name="submit_kc" datasource="#DS#">
	insert into
#kch#(office,classification,title,day,month,year,location,participants,purpose,agenda,item)
	values('#form.office#',
		'#form.classification#',
		'#trim(form.title)#',
		'#form.day#',
		'#form.month#',
		'#form.year#',
		'#trim(form.location)#',
		'#trim(form.participants)#',
		'#trim(form.purpose)#',
		'#FullFilePath#',
		'#FullFilePath1#'
)
</cfquery>
</cfif>

Open in new window

0
Comment
Question by:Shwapy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 19

Accepted Solution

by:
erikTsomik earned 2000 total points
ID: 24795881
ok I believe the problem is here
If you do not upload anything you should not have insert anything into the dataabse

SO just do this
<cfquery name="submit_kc" datasource="#DS#">
        insert into
#kch#(office,classification,title,day,month,year,location,participants,purpose<cfif agenda neq "">,agenda</cfif>,<cfif form.Item neq "">item</cfif>)
        values('#form.office#',
                '#form.classification#',
                '#trim(form.title)#',
                '#form.day#',
                '#form.month#',
                '#form.year#',
                '#trim(form.location)#',
                '#trim(form.participants)#',
                '#trim(form.purpose)#'
<cfif form.agenda neq "">
                ,'#FullFilePath#',
</CFIF>
<CFIF FORM.item neq "">
                '#FullFilePath1#'

</cfif>
)
</cfquery>

That will soleve the problem.
Also get to the habit of using <cfqueryparam
0
 

Author Closing Comment

by:Shwapy
ID: 31600674
Thanks for your help!!
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question