?
Solved

Assigning form object names to cf variables?

Posted on 2003-02-28
17
Medium Priority
?
599 Views
Last Modified: 2013-12-24
I have a dynamic form that populates based on an employee list. The form contains the following for each employee
textbox name trnDate#idx# value date of training
textbox name empName#idx# value employee name
hidden name empID#idx# value unique employee number
checkbox name trn#idx# value true

the employee list can be from 0 to 6000 entries i need to process the sub mission based upon the checkbox being selected. How can I assign the NAME of a form variable to a cf variable in a loop to determine the form variable is true? As in:
<cfloop index="idx" from="1" to="#var#">
   <cfif form.trn#idx#>
      <cfoutput>
         trnDate#idx#
         empName#idx#
         empID#idx#
      </cfoutput>
   </cfi>
</cfloop>

it doesn't work assignment of the form field names is what is giving me a hard time.
0
Comment
Question by:James Rodgers
[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
  • 4
  • 3
  • 3
  • +3
17 Comments
 
LVL 1

Expert Comment

by:jeffryan
ID: 8043383
How about trying this:

<cfloop index="idx" from="1" to="#var#">
  <cfif isdefined("form.trn#idx#")>
     <cfoutput>
        trnDate#idx#
        empName#idx#
        empID#idx#
     </cfoutput>
  </cfi>
</cfloop>
0
 
LVL 1

Expert Comment

by:jeffryan
ID: 8043401
How about trying this:

<cfloop index="idx" from="1" to="#var#">
  <cfif isdefined("form.trn#idx#")>
     <cfoutput>
        trnDate#idx#
        empName#idx#
        empID#idx#
     </cfoutput>
  </cfi>
</cfloop>
0
 
LVL 1

Accepted Solution

by:
Concigliere earned 600 total points
ID: 8043863
the isdefined method works fine but if you want to keep going with the true youll STILL have to use isdefined unless you set the vars to false that arent ture...

<cfoutput>
<cfloop index="idx" from="1" to="#var#">
 <cfif isefined('form.trn#idx#') AND form["trn#idx#"]>

       trnDate#idx#<br>
       empName#idx#<br>
       empID#idx#<br><br>

 </cfif>
</cfloop>
</cfoutput>

to dump the isdefined method youll need to set dynamic params for all your possible form fields with something like....


<cfloop query="queryname">
<cfparam name = "form.trn#id#" default = "fasle">
</cfloop>

then you could just use....

<cfoutput>
<cfloop index="idx" from="1" to="#var#">
 <cfif form["trn#idx#"]>

       trnDate#idx#<br>
       empName#idx#<br>
       empID#idx#<br><br>

 </cfif>
</cfloop>
</cfoutput>
0
How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

 
LVL 4

Expert Comment

by:crosenblum
ID: 8044007
It is much easier to use the same form name instead of dynamic form names.

Then do a listlen on the submitted form
For example your form name is employee_names

<cfif isdefined("form.fieldnames")>
<cfset emp_count = listlen(form.employee_names)>
<Cfif emp_count eq 0>
handle as if only 1 record sent.
<cfelse>
<cfloop from=1 to=#emp_count# index=x>
  <cfquery name="add_record" datasource="whatever">
    insert into employees (name)
    values ('#listgetat(form.employee_names,x)#')
  </cfquery>
</cfloop>

This technique gets more complicated with more form elements.

But it is very easily doable.

Because everything is a form, you can loop and take form data and make it into a query, via querysetcell if you had a need for sorting form data.

As I have had to do, on a few occasions.

The key is whether multiple/single form element data is sent...You use listlen to determine number of elements in the form.

Then do a listgetat(form.formname,position) to grab the data from the form.formname

I hope that helps...

Exploring The Truth
http://mindstream.blogspot.com
0
 
LVL 17

Expert Comment

by:anandkp
ID: 8046700
give this a try

<CFLOOP index="idx" from="1" to="#var#">
<CFIF isDefined('form.trn#idx#')>
          <CFOUTPUT>
               #Evaluate('trnDate#idx#')#
               #Evaluate('empName#idx#')#
               #Evaluate('empID#idx#')#
          </CFOUTPUT>
</CFIF>
</CFLOOP>

let me know

K'Rgds
Anand
0
 
LVL 4

Expert Comment

by:crosenblum
ID: 8046965
I just personally dislike dynamic form names.

It has no point, when you can use common sense form names, and just pass it, and convert it into a list.

Meaning any form element that has multiple values will be like a list.

example someone typed in their first name twice in two seperate forms going to the same action page

form.firstname = craig,craig

so if you do listlen(form.firstname) will equal 2

then you can loop thru that, and if there are other expected fields to be list format.

you can do like above...

loop thru list length - use any form element it doesn't matter as long as it has equal length as the rest of the fields.


0
 
LVL 1

Expert Comment

by:jeffryan
ID: 8047962
Maybe he is using dynamic form names because he is outputting a query of multiple employees in one form and wants to work with mulitple records in the one form.
0
 
LVL 4

Expert Comment

by:crosenblum
ID: 8050300
dynamic form names are an old idea, when there are much better ways of handling it.

Such as having the same form name. And because each form element will have multiple values, they can be treated like list elements.

like my example did say before...

The key with data manipulation is:

a. understanding how to easily convert one kind of data to another. Because this will be useful in current and future applications.
b. visualizing the data, being able to see it in 3d, visualize how the application changes, manipulate data
c. understand the relationships between applications.

have fun!
0
 
LVL 1

Expert Comment

by:Concigliere
ID: 8052416
I don’t think your quite following the situation crosenblum…(or maybe im not) but that’s besides the point here…

You don’t like dynamic form names? Fine, don’t use them…rewrite code over and over…

But its an opinion…say it once and move on but don’t try and push it onto people here that are trying to do something the right way.

Try accomplishing something like this without them….

Create a dynamic survey admin tool where the admin can log in
.…add the survey
….add multiple questions to the survey (as many as he likes) (required yes/no)
….add multiple possible answer per question (as many as he likes) (radio buttons)
….give each question the option of having and “Other” answer with a text field for specification of answers

Once it is created 3 dynamic tables are created as well

…one holds all possible questions for that particular survey
…two holds all possible answers per question of table one
…three holds all results of every submission of the current survey

how would you build the forms to get the survey to the user?
….dynamically
how would you write a validation of the fields to make sure the required questions were answered?
….dynamically
how would you capture all results for entering into the database?
….dynamically
how would you display percentage results of a dynamic survey when you have no idea what info is in the database?
….dynamically

crosenblum
“dynamic form names are an old idea, when there are much better ways of handling it.”

you may be able to do it without dynamic form names…but it will limit the application making it far from “better”, non-reusable and not resalable without drastic modification…

Dynamic = Reusable = mo money mo money


sorry if i come off as an ass

just woke up, no caffeine, and tired of being left with the job of trampling through code of developers who didnt last becuz of their static coding habits
0
 
LVL 17

Expert Comment

by:anandkp
ID: 8055262
dynamic code wld help u out with :

1. less code
2. easy maintenance
3. no overheades ie :if it works for one - it will work for other as well
4. quick debugging
5. easy understanding

depends on the way u look at it - if u try & look at the brighter side - u can find benefits in it ... its a personal opinion & everyone is free to do things - the way they wanna do.

so lets see what jeter_48 has to say abt this ... i mean the answere's posted for him !

Cheers
Anand
0
 
LVL 4

Expert Comment

by:crosenblum
ID: 8058730
So would the new way, it's just easier to track down where and why a certain thing exists if it uses common sense naming convention.

0
 
LVL 10

Expert Comment

by:substand
ID: 8060541
I think this is the simplest and most code/server efficient method:

1) Name your check boxes all the same.
2) make the value of each checkbox the ID of the record it represents.

3) loop through the values in that form field (they will be returned as a comma delimited list).  These values are the ids you want to manilpulate.  So instead of checking every single check box to see if it was checked, you only check the ones that were.

the loop would be (if you name the checkbox idsToManipulate)

<cfloop list="#form.trn#" index="idx">
  trnDate#idx#<br>
  empName#idx#<br>
  empID#idx#<br><br>
</cfloop>

that way, you only need to change one line in your form page, the one that sets the name to trn#idx#, just call it "trn"





0
 
LVL 10

Expert Comment

by:substand
ID: 8060563
sorry, i meant "if you name the checkboxes "trn", not "idsToManipulate"
0
 
LVL 25

Author Comment

by:James Rodgers
ID: 8071798
There are some good comments and answers here, but I am having a hard time picking the best answer as the solution I need seems to be a selection of code snippets and comments from several people.

As for the dynamic vs static code I always use dynamic where possible. A well designed and coded dynamic function/code block can drastically reduce the need for rewrites, also designing for user requirements means anticipating what the next level of application functionality your code can accommodate, will need to accommodate and should accommodate.
An example: my first project here was to develop a dynamic reporting application that had to work until DEC 31 of the current year, on January 1 the user requirement was that with a few changes the application would work again until the end of the year, why code this? it meets the user/clients needs if it works for 1 year at a time, but why waste time and resources rewriting a few lines of code evey January when in the initial developemnt a few extra lines of code would allow the application to run forever? and what if a new developer was too green to understand the code how long would it take for that person to walk through the static code to determine where/what to change? a day, a week? how much money do you want to spend? because I can create code that you would need to rewrite on a daily basis if you are willing to pay me to do that but my time is better spent creating new DYNAMIC applications, job security isn't rewriting code you should have done right the first time, job security comes from creating excellent work and making YOU too valuable to lose!

I will select the BEST answer later today. Thanks to all for there copmments and responses.
0
 
LVL 25

Author Comment

by:James Rodgers
ID: 8071832
Thanks,
While this answer is actually and expanded version of the earlier answer it meets the needs of my application more than the earlier answer.

Again thanks to all who participated in this discussion.
0
 
LVL 1

Expert Comment

by:Concigliere
ID: 8072050
<quote>As for the dynamic vs static code I always use dynamic where possible. A well designed and coded dynamic function/code block can drastically reduce the need for rewrites, also designing for user requirements means anticipating what the next level of application functionality your code can accommodate, will need to accommodate and should accommodate. </quote>

well said!!

glad to help and I do appalogize for, more or less, turning your query into a debate &#9786;
0
 
LVL 17

Expert Comment

by:anandkp
ID: 8077503
gr8 going

btw - did u try out the option i had posted - just wanted to know - if it worked out for u !

K'Rgds
Anand
0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

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.
What You Need to Know when Searching for a Webhost Provider
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

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