Solved

Determine existing form fields?

Posted on 2003-11-18
6
685 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 19

Accepted Solution

by:
cheekycj earned 25 total points
ID: 9772815
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
ID: 9776418
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
ID: 9779168
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
ID: 9784764
then i don't think u can change what u r doing right now..

Regards
Hart
0

Featured Post

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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