Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Empty Form Fields causing problems 1

Status
Not open for further replies.

DrDan2

Technical User
Nov 22, 2002
24
GB
Hi there. I have a form that sends data to a coldfusion page. Works great. Displays the entered data, can upload a picture and everything... BUT!!!!

When a field in the form is left blank, it won't work. Fields will have to be left blank every now and then so how I do I get this to work? Any help would be appreciated. Thanks.
 
use CFPARAM to assign all form fields a default value at the top of the action page

<CFPARAM NAME=&quot;form.foo&quot; DEFAULT=&quot;^none&quot;>

then test the form field before acting on the value

<CFQUERY>
update mytable
set updatedby = #session.userid#
<CFIF form.foo NEQ &quot;^none&quot;>
, foo = #form.foo#
</CFIF>
<!--- set other fields --->
</CFQUERY>

rudy
 
Thanks. I'll try that right away, but being lazy, isn't there away of settinf the default for all the fields at once instead of doing it for each indivual one. I have quite a few.
 
No. Still Doesn't work. I get a page telling me that the thing can't be zero length. This is my code so far. The form itself is a page called &quot;Test4.HTM&quot;
It's a bit long but the bit you said to put in is right at the top. (CFPARAM)


<HTML>

<CFPARAM NAME=&quot;Test4.Country&quot; DEFAULT=&quot;^None&quot;>

<CFFILE ACTION=&quot;Upload&quot; FILEFIELD=&quot;Form.Logo&quot;
Destination=&quot;C:\CFusionMX\ NAMECONFLICT=&quot;Overwrite&quot; ACCEPT=&quot;image/gif, image/jpg, image/pjpeg, image/jpeg&quot;>

<CFSET NewLogo = File.Clientfile>

<CFQUERY DATASOURCE=&quot;DiveSchools&quot; Name=&quot;NewImage&quot;>
INSERT INTO DiveData(Logo, ContactName, OrgName, Organisation, Description, City, Address1,
Address2, PostCode, Country, Tel, Fax, Email, Website, Facilities)
VALUES ('#NewLogo#','#ContactName#','#OrgName#','#Organisation#','#Description#','#City#',
'#Address1#','#Address2#','#PostCode#','#Country#','#Tel#','#Fax#','#Email#',
'#Website#','#Facilities#')
</CFQUERY>

<CFQUERY DATASOURCE=&quot;DiveSchools&quot; Name=&quot;LogoQuery&quot;>
Select *
From DiveData
Where Logo='#NewLogo#' AND OrgName='#OrgName#'
</CFQUERY>

<HEAD><TITLE>AAAARGH</TITLE></HEAD>

<BODY>

<CENTER><H2>WOOHOO! This is Your Image.</H2><br>

<CFOUTPUT QUERY=&quot;LogoQuery&quot;>
<IMG SRC=&quot;C:\CFusionMX\
Your ID Number is DC#ID_CODE#. Please quote this number if you need to
contact me.<p>

<B>Your Current Details are as follows:</B><br>
Contact Name: #ContactName#<br>
Business Name: #OrgName#<br>
Organisation: #Organisation#<br>
Summary of Business: #Description#<br>
City: #Description#<br>
Address 1: #Address1#<br>
Address 2: #Address2#<br>
Post/Zip Code: #Postcode#<br>
Country: #Country#<br>
Tel: #Tel#<br>
Fax: #Fax#<br>
E-Mail: #Email#<br>
Website: #Website#<br>
Facilities: #Facilities#<br>

</CFOUTPUT>
</CENTER>

</BODY>
 
Sorry. Ignore all that. All I had to do was cahnge the properties in the Access Database, but I still have trouble with the Logo which can be uploaded. If that is left empty, it doesn't work. This is my code for that.

<CFFILE ACTION=&quot;Upload&quot; FILEFIELD=&quot;Form.Logo&quot;
Destination=&quot;C:\CFusionMX\ NAMECONFLICT=&quot;Overwrite&quot; ACCEPT=&quot;image/gif, image/jpg, image/pjpeg, image/jpeg&quot;>

<CFSET NewLogo = File.Clientfile>
 
All you need do is add a condition in your File Upload Action Page.

<cfif form.your_image neq &quot;&quot;>

Then do the upload stuff


<cfelse>

&quot;Please ensure that you select a file to upload&quot;

<input type=&quot;button&quot; value=&quot;Back&quot; onclick=&quot;history.go(-1)&quot;>

</cfif>
 
Pretty obvious isn't it. lol. Thanks. :)
 

Macromedia recommends using:

Code:
<cfif len(trim(form.your_image)) GT 0>

instead of

Code:
<cfif form.your_image neq &quot;&quot;>


Take it as you will... I'm only the messenger [wink]


Hope it helps,
-Carl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top