Determine existing form fields?
Posted on 2003-11-18
I've created a handy include template, PreserveForm.inc, that I use to generate hidden input fields populated the FORM object. I use it to perpetually post form data to the next template, and the next, and so on, until I'm ready to update the database.
However, it doesn't work correctly if I duplicate existing fields. If a form field is posted to an action page that then creates an input text field with the same name, the value gets appended with a preceding comma.
I get around this by creating a list of fieldnames in the variable PreserveExclude.
Here's how you call it:
<cfset PreserveExclude = "FIELD1,FIELD2,FIELD3">
And here's the include file:
Generate hidden form fields from existing form object. Must be included just
before the end </form> tag after all input fields.
<cfloop list="#form.fieldnames#" index="f">
<cfif NOT IsDefined("PreserveExclude")
OR ListFindNoCase(PreserveExclude, f) IS 0>
<cfset FEval = "ListLast(form." & f & ")">
<input name="#f#" type="Hidden" value="#Evaluate(FEval)#">
So, it only creates hidden fields that are not in the PreserveExclude list. I'd like to get rid of PreserveExclude.
But in ColdFusion, let's say you have a complicated series of conditional include files that create <INPUT> fields. You cannot be sure which fields were created.
So, the question is: Is there a way in ColdFusion to determine which form fields already exist?
Thanks in advance!