Skip to main content
Inspiring
December 3, 2008
Question

CFPARAM How to?

  • December 3, 2008
  • 6 replies
  • 855 views
I'm trying to find out if this is possible with the <cfparam> tag.

One Column Table (my_table)

my_column
a
b
c
d
.
.
z

This table is read to produce an a web page with <input type="radio" name="#my_column#" value="No" /> <input type="radio" name="#my_column#" value="Yes" /> for all the values of the table.

So, the value of the column is the name of the <input> tag.

<input type="radio" name="a" value="No" />
<input type="radio" name="a" value="Yes" />
<input type="radio" name="b" value="No" />
<input type="radio" name="b" value="Yes" />
<input type="radio" name="c" value="No" />
<input type="radio" name="c" value="Yes" />
.
.
etc

Now the question. On the calling page, is there a way to loop through the table and retrieve the value of No/Yes for each value in the table? Meaning, I loop through a..z but retrieve the value of No/Yes for form.A, form.B, form.C, form.D since that's the name of the input tag.

<cfloop query="my_table">
<cfif IsDefined("form."& my_column)> (form.a, form.b, form.c....form.z)
print the value of "a" which should be either No or Yes
</cfif>
</cfloop>
    This topic has been closed for replies.

    6 replies

    Inspiring
    December 5, 2008
    while evaluate might work, array notation will work faster.
    NettlesDAuthor
    Inspiring
    December 5, 2008
    I found my solution yesterday after working with it some.

    The solution is a simple tag of evaluate.

    <cfquery name="test" datasource="...">
    SELECT tag_name FROM mytable ORDER BY tag_name ASC
    </cfquery>

    <cfloop query="test">
    <cfif IsDefined("form."& tag_name)>
    #evaluate(tag_name)#
    </cfif>
    </cfloop>
    Inspiring
    December 5, 2008
    <cfquery name="test" datasource="...">
    SELECT tag_name FROM mytable ORDER BY tag_name ASC
    </cfquery>

    <cfoutput query="test">
    <cfparam name="form[tag_name]" default="No">
    form.#tag_name# value is: #form[tag_name]#<br />
    </cfoutput>

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    NettlesDAuthor
    Inspiring
    December 4, 2008
    Maybe this is clearer.

    CREATE TABLE test
    (
    tag_name VARCHAR2(20 BYTE)
    )

    insert into test

    (tag_name)

    values
    ('bottle')


    Web Page 1

    <cfloop query="test">
    <input type="radio" name=" #tag_name#" value="No" />
    <input type="radio" name=" #tag_name#" value="Yes" />
    </cfloop>

    The input tag will read:
    <input type="radio" name=" bottle" value="No" />
    <input type="radio" name=" bottle" value="Yes" />

    <input type="submit" name="Submit" value="Submit" />

    Web Page 2

    We know that a parameter of "Bottle" and "Submit" was submitted to this form. Since the table has the name of the tag_name stored in the table, how can I loop through the table and retrieve the value that "Bottle" was passed with.

    <cfloop query="test">
    <cfif IsDefined(" form."& tag_name)> (should read form.bottle)
    What is the value of "bottle" that was passed in?
    should be either No or Yes

    </cfif>
    </cfloop>
    Inspiring
    December 5, 2008
    quote:

    Originally posted by: NettlesD
    Maybe this is clearer.

    CREATE TABLE test
    (
    tag_name VARCHAR2(20 BYTE)
    )

    insert into test

    (tag_name)

    values
    ('bottle')


    Web Page 1

    <cfloop query="test">
    <input type="radio" name=" #tag_name#" value="No" />
    <input type="radio" name=" #tag_name#" value="Yes" />
    </cfloop>

    The input tag will read:
    <input type="radio" name=" bottle" value="No" />
    <input type="radio" name=" bottle" value="Yes" />

    <input type="submit" name="Submit" value="Submit" />

    Web Page 2

    We know that a parameter of "Bottle" and "Submit" was submitted to this form. Since the table has the name of the tag_name stored in the table, how can I loop through the table and retrieve the value that "Bottle" was passed with.

    <cfloop query="test">
    <cfif IsDefined(" form."& tag_name)> (should read form.bottle)
    What is the value of "bottle" that was passed in?
    should be either No or Yes

    </cfif>
    </cfloop>

    query.columnlist combined with array notation will still work. You just have to get the syntax right. Look at Azadi's answer for the syntax.
    December 4, 2008
    So are you having the user select the items (A-Z) that they want to display and then showing the corresponding value from the database?
    NettlesDAuthor
    Inspiring
    December 4, 2008
    quote:

    Originally posted by: eightcharacters
    So are you having the user select the items (A-Z) that they want to display and then showing the corresponding value from the database?


    No. What I'm trying to say is; the name of the <input> tag (name="") is stored in a column in a table. If the value of that column has "a...z" then each tag would be like this:

    <input type="radio" name=" a" value="No" />
    <input type="radio" name=" a" value="Yes" />
    <input type="radio" name=" b" value="No" />
    <input type="radio" name=" b" value="Yes" />
    <input type="radio" name=" c" value="No" />
    <input type="radio" name=" c" value="Yes" />
    <input type="radio" name=" z" value="No" />
    <input type="radio" name=" z" value="Yes" />

    Since the names of the tags are stored in the table, I should be able to loop through the table and find out what value "No or Yes" was passed within the <input> tag. What I can't figure out is how to retrieve the value of the <input> tag from reading the values of the column since the names will match.

    Given my <input> tags above, my receiving page would have cfparam tags as follows:

    <cfparam name=" a" default="">
    <cfparam name=" b" default="">
    <cfparam name=" c" default="">
    <cfparam name=" z" default="">

    Since the names of these cfparams tags are in a table, I want to be able to read from the table and associate the value from the column (the name of the input tag) to the actual value that was passed in to the page.

    my_table --> my_colum ---> Value --- > a --> <input type="radio" name=" a" value="No" /> ---><cfparam name=" a" default=""> --> what is the value that is passed in.

    Inspiring
    December 3, 2008
    You can use the columnlist variable of cfquery. Details are in the cfml reference manual under <cfquery>

    Oh, you'll have to use array notation to make it work.
    NettlesDAuthor
    Inspiring
    December 3, 2008
    I looked up columnlist and I don't think that will help me. That just gives me a list of the columns of the query. That's not what I'm after.

    In my example, the "result_name.columnList" would return "my_column". The actual name of the <input> tag is the value of "my_column", which is, a, b, c, d....z.

    Once these are passed to the next page, I'm trying to retrieve the value from looping through the table since that holds the name for each <input> tag.

    <input type="radio" name="a" value="No" />
    <input type="radio" name="a" value="Yes" />
    <input type="radio" name="b" value="No" />
    <input type="radio" name="b" value="Yes" />
    <input type="radio" name="c" value="No" />
    <input type="radio" name="c" value="Yes" />

    The names of the <input> tags are stored in the table. I want to loop through the table to find out the value that is being passed with the <input> tag.

    <cfloop query="my_table">
    <cfif IsDefined("form."& my_column)> (form.a, form.b, form.c....form.z)
    print the value of "a" which should be either No or Yes
    </cfif>
    </cfloop>