?
Solved

Determine existing form fields?

Posted on 2003-11-18
6
Medium Priority
?
687 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 100 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 100 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

743 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