Solved

Determine existing form fields?

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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 …
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

12 Experts available now in Live!

Get 1:1 Help Now