Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

#form.#variable## ?

Status
Not open for further replies.

LenLindquist

IS-IT--Management
Oct 17, 2002
31
US
I am attempting to evaluate a form field on the action page where the field names themselves originally came from a query.

So, when evaluating the form variable, the variable itself is #variable#, but I need something like #form.#variable##. However, this syntax is not valid.

Can anyone help?

Much appreciated,
Len
 
gonna smack yourself for this, you used all the right terminology too...

#Evaluate("form." & variable)# or #Evaluate("form.#variable#")#

Tony Did I help?
Vote!
 
I tried what you suggested (including smacking myself) and, unfortunately, those didn't work either. Thanks for trying, though. I think I may be doing something in a way that I'm really not supposed to be doing it. Here's more info:

I have a database that may have from zero to many entries in a particular field. Each entry is displayed on the form (using a simple query as normal) with a yes/no type checkbox selection (it's an electronic mailing list signup form).

Since I want the form to dynamically change based on the contents of the database, I decided to name each of the form variables based on that particular record as follows:

..
<cfinput type=&quot;checkbox&quot; id=&quot;#key#&quot; name=&quot;#key#&quot; />#listname# (#description#)
..

So the variable that is submitted to the action page that I'd like to work with is form.#key#, but CF seems to require that #'s surround &quot;form&quot; as well.

One of my variables that doesn't change is called #name#, and I can refer to it as #form.name# as normal. But I can't refer to the key as #form.key# because it isn't #form.key#, it's #form.#key##. But that's not valid syntax and it also complained about the #Evaluate() functions listed above. So far, I haven't been able to find the right syntax to even simply display one of these variables.

Perhaps what I should be doing is using an array for this application? I haven't done that in ColdFusion yet so maybe I'm just being lazy about this and doing it WRONG. I'll try that.

Thanks for your help.
Len
 
Try this... #Form.Fieldnames# it will return a list of your form fields... does the list contain &quot;key&quot;?

(I'm assuming key is numeric)

BTW.. when working with checkboxes what you would want to do is have one standard name for all checkboxes &quot;fkey&quot; let's say and then the value is different.. when you call #form.fkey# you'll get a list of selected values.. Let's say this was your naming and valuing syntax

Code:
<INPUT type=&quot;checkbox&quot; name=&quot;fkey&quot; value=&quot;#key#&quot;>
<INPUT type=&quot;text&quot; name=&quot;email#key#&quot;>

You could insert into the database with this methodology...

Code:
<CFLOOP list=&quot;#form.fKey#&quot; index=&quot;k&quot;>
 <CFQUERY....>
  INSERT INTO MyTable(dKey,dEmail)
  VALUES ('#k#','#evaluate(&quot;form.email#k#&quot;)#
 </CFQUERY>
 <CFOUTPUT>Email Address #k# inserted into the database!</CFOUTPUT>
</CFLOOP>

What version of CF are you using? Did I help?
Vote!
 
I try to avoid using the Evaluate() whenever possible, it takes longer than other methods.

The FORM scope is actually a structure. The followinf variable can be writen 1 of 2 ways:

#FORM.myvar#
#FORM[&quot;myvar&quot;]#

or, if you are passing a variable it can be:
<cfset string = &quot;myvar&quot;>
#FORM[string]#

or

<cfset string = &quot;var&quot;>
#FORM[&quot;my&quot; & string]#
#FORM[&quot;my#string#&quot;]#

So instead of writing it:
#form.#variable##

You would write it one of these ways, the last is perfered:
#form[#variable#]#
#form[&quot;#variable#&quot;]#
#form[variable]#

Keep in mind, however, when a checkbox is passed to the next page, if it is not checked the the variable doesn't exists. So be sure to add:
<cfparam name=&quot;form.#variable#&quot; default=&quot;No&quot;>

Functions to avoid
You should avoid the functions listed below. They tend to be slow, hard to read, or produce unexpected results. Use their alternatives instead (or simply rewrite your code to avoid using the function).

Avoid... Use this instead...
evaluate() Rewrite your code to avoid using this function.
iif() <cfif ...>
structFind() struct.key
incrementValue(x) x = x + 1 - tleish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top