Solved

Determine existing form fields?

Posted on 2003-11-18
6
681 Views
Last Modified: 2013-12-24
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">
<cfinclude template="PreserveForm.inc">

And here's the include file:

<!--- PreserveForm.inc:
Generate hidden form fields from existing form object.  Must be included just
before the end </form> tag after all input fields.
--->

<cfoutput>

<cfif IsDefined("form.fieldnames")>
      <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)#">
            </cfif>
      </cfloop>
</cfif>

</cfoutput>

So, it only creates hidden fields that are not in the PreserveExclude list.  I'd like to get rid of PreserveExclude.

Determining existing form fields in JavaScript is simple, just make sure they're created before looking for them.  But that's client side.

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!
0
Comment
Question by:CarlsonCo
  • 2
6 Comments
 
LVL 19

Accepted Solution

by:
cheekycj earned 25 total points
Comment Utility
I think the way you are doing it is the only way.  Remember CF is executed on the server side before your HTML form is rendered.  So CF doesn't know what the elements/fields of your form are.  JavaScript executes client side so it can easily find out.

Probably not what you wanted to hear but unfortunately a shortcoming of Serverside scripting.

CJ
0
 
LVL 11

Assisted Solution

by:hart
hart earned 25 total points
Comment Utility
just a suggestion if u r forming hidden fields

then why not give the name as hidden_fielname.

this will differentiate it from the other normal fields and ur purpose will be solved.

Regards
Hart
0
 

Author Comment

by:CarlsonCo
Comment Utility
That would mean rewriting all form and action pages throughout the system to be aware of the existance of hidden_fieldname.  I'm trying to avoid that.
0
 
LVL 11

Expert Comment

by:hart
Comment Utility
then i don't think u can change what u r doing right now..

Regards
Hart
0

Featured Post

Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

Join & Write a Comment

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now