Andrew, Check out qForms: http://www.pengoworks.com/qforms/
Using the API will simply what you're trying to do greatly. One of the things that you'll be able to do is pass a JS-based structure (which you can get by using <cfwddx action="cfml2js">) to the setFields() method, which will allow you to populate existing values or default values with ease. -Dan > -----Original Message----- > From: Andrew Peterson [mailto:[EMAIL PROTECTED]] > Sent: Thursday, September 12, 2002 2:58 PM > To: CF-Talk > Subject: Validating form fields with a structure and loop > > Hi, > > I wanted a little more than the basic form field validation offered by > CFForm, and so I am validating form field data by placing error messages > in a structure called ErrorStruct and setting the form field name as the > key, so that later I can output it, like so: > > <!--- make sure field is numeric, etc. ---> > <cfif not IsNumeric(form.WithdrawPrincipal)> > <cfset StructInsert(ErrorStruct, "WithdrawPrincipal", "Withdrawl > Principal is not a number")> > </cfif> > > Then, later, reset the form field like so: > > <cfif structKeyExists(ErrorStruct,"WithdrawPrincipal")> > <cfset form.WithdrawPrincipal=""> > </cfif> > > And then of course in the form, the default value is like so: > > <input type="text" name="withdrawPrincipal" > value="#form.WithdrawPrincipal#"> > > Since I've got a lot of fields to validate, I'm trying to loop over the > structure keys and reset values that way, thus simplifying my code. Or > so it would seem: > > <cfset lstNumericFields = > "Month,Year,BYPrincipal,BYInterest,AddPrincipal,AddInterest,WithdrawPrin > cipal,WithdrawInterest,EYPrincipal,EYInterest,EYTotal"> > <cfloop list="#lstNumericfields#" delimiters="," index="ii"> > <cfif structkeyExists(ErrorStruct,"#ii#")> > <cfset myFormField="form.#ii#"> > <cfset myformfield.value="0"> > <cfoutput>#myformfield# = #myformfield.value#<br></cfoutput> > <!--- this outputs to: > form.month = 0 > form.year = 0 > form.byprincipal = 0 etc > ---> > </cfif> > </cfloop> > > I didn't think this through, however, because there is no way to place > the default value of each of these fields in the actual form, which is > located outside of the loop, is there? In other words, the following > code will not work... > > <input type="text" name="#myformfield#" value="#myformfield.value#> > > ..unless I place it in the loop. And since there is so much other > formatting going on in the form, there really is no way to do that. So > now I'm back to manually checking the existence of each key. > (Copy/Paste, Copy/Paste) Is there a more elegant way? > > Sincerely, > > Andrew > > > ______________________________________________________________________ Get the mailserver that powers this list at http://www.coolfusion.com FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/[email protected]/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

