Tim,
There are a couple of issues here. I assume you know that you should be scoping the
variables you are setting with CFPARAM. However, if you DID do this it still wouldn't
matter, since the form fields are getting passed even though they ARE blank. Maybe
you were hoping to get away with this by not scoping the variables in your CFPARAM
code.
To make this work, you could make a list and loop through it, checking to make sure
each field is blank before you set it. Since you have two fields that need to be
numeric, you could set those manually first.
<cfif Trim(FORM.Pages) EQ "">
<cfset Pages = 0>
</cfif>
<cfif Trim(FORM.Year) EQ "">
<cfset Year = 0>
</cfif>
<!--- Make a list of the unrequired form fields --->
<cfset UnrequiredFields =
"Service,Position,Ndate,Volume,Issue,Authors,ArticleTitle,Source,Other">
<!--- Loop through the list, so each one can be checked for a valid value --->
<cfloop list="#UnrequiredFields#" index="ThisField">
<!--- If the unrequired variable is blank . . . --->
<cfset rs = IIF(Trim(Evaluate("FORM." & ThisField) EQ
""),"SetVariable(ThisField,'N/A')","SetVariable(ThisField,Evaluate('FORM.' &
ThisField))")>
</cfloop>
Sorry about that long IIF; I am trying to wake my brain up as opposed to being messy
;) You could it out to a conditional check and a couple of cfsets if you want to.
Now you can plug this code into your page without changing your SQL code since this
checks each form field with the proper scope (FORM.) but creates a local variable for
each field that needs a default value; if the unrequired variable HAS a value, then
the code will set the proper form field to a local variable. Scope Scope Scope!
Now if you have any other non-required fields, you can just add them to the list,
provided they will need a value of "N/A". You could expand on this and make sub list
within that list, so that you could specify default values for each variable. This
example doesn't take into account that you should always make sure your form action
pages test for the existence of form fields before processing to avoid errors.
-Andy
> -----Original Message-----
> From: Tim [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, February 20, 2001 10:05 AM
> To: CF-Talk
> Subject: How to check form fields for content and modify?
>
>
> I have a form that does not require all fields to be
> filled out. On the action page, I need to check the
> non-required fields for content, and if empty place
> "n/a" or a zero in the field before the record is
> added to the database. I tried using <cfparam>, but
> it does not seem to work. The code is:
>
> <cfparam name="Pages" default=0>
> <cfparam name="Year" default=0>
> <cfparam name="Service" default="N/A">
> <cfparam name="Position" default="N/A">
> <cfparam name="Ndate" default="N/A">
> <cfparam name="Volume" default="N/A">
> <cfparam name="Issue" default="N/A">
> <cfparam name="Authors" default="N/A">
> <cfparam name="ArticleTitle" default="N/A">
> <cfparam name="Source" default="N/A">
> <cfparam name="Other" default="N/A">
>
> <CFQUERY NAME="qInsert" DATASOURCE="request">
> INSERT INTO data (Location, Requested, Service, TDate,
> Position, Extension, NDate, Format, PeriodicalTitle,
> Volume, Issue, Authors, Pages, Year, ArticleTitle,
> Source, NLM, Other, Status)
> Values ('#form.Location#', '#form.Requested#',
> '#Service#', '#TDate#', '#Position#',
> #form.Extension#, '#NDate#', '#form.Format#',
> '#form.PeriodicalTitle#', '#Volume#', '#Issue#',
> '#Authors#', #Pages#, #Year#, '#ArticleTitle#',
> '#Source#', '#NLM#', '#Other#', '#Status#')
> </CFQUERY>
>
> Any other ideas?
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists