Solved

Determine existing form fields?

Posted on 2003-11-18
6
686 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 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