• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

checkbox hell

Guest
Oct 13, 2008 Oct 13, 2008

Copy link to clipboard

Copied

I'm lost on this as everything I've found says to simply use cfparam but this doesn't seem to work for me. Running this on IIS and Coldfusion 7.
TOPICS
Advanced techniques

Views

335

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 13, 2008 Oct 13, 2008

Copy link to clipboard

Copied

> I'm lost on this as everything I've found says to simply use cfparam but this
> doesn't seem to work for me.

Do you want to elaborate on "doesn't work for you"?

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 13, 2008 Oct 13, 2008

Copy link to clipboard

Copied

Using the associative array notation for the form struct enables you to do away with the evaluate() function. Here are four suggestions:

bgcolor="##006699"

<cfparam name="#form[g & "mark"]#" default="0" type="Boolean">

<cfif form[g & 'mark'] neq 0>

#form[g & 'mark']#, #form[g & 'sfiid']#, #form[g & 'name']#, #form[g & 'package']#, #form[g & 'total']#, #form[g & 'hashinfo']#<br>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 13, 2008 Oct 13, 2008

Copy link to clipboard

Copied

radico wrote:
> I'm lost on this as everything I've found says to simply use cfparam but this doesn't seem to work for me...
> ..
> <input type="checkbox" name="#count#mark" value="1" checked visible="Yes" enabled="Yes">
> <cfparam name="#Evaluate("form.#g#mark")#" default="0" type="Boolean">

Evaluate() is causing the very error you are trying to prevent. The evaluate() function will execute before the cfparam code. So the form field still does not exist yet, which causes an error.

Not that you need to use evaluate anyway. Just use the string name:

<cfparam name="form.#g#mark" default="0" ...>

> #evaluate('form.#g#mark')#,#evaluate('form.#g#sfiid')#,#evaluate('form.#g#name')#,>....

To extract the values of dynamic form fields use array notation, instead of evaluate()

#form[g &"mark"]#
#form[g &"sfiid"]#
....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 13, 2008 Oct 13, 2008

Copy link to clipboard

Copied

Radico,
-==cfSearching==- opens up a question. Your original code suggests that the cfparam's name attribute is #form[g&'mark']#, the value of the form field. He suggests the name of the form field, form.#g#mark, which is the one I would also expect. You have to make a choice.



Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 15, 2008 Oct 15, 2008

Copy link to clipboard

Copied

LATEST
Hi,

I have attached a set of functions that I use to
- Dynamically create these fieldnames
- Read the value from these dynamic fieldnames
- Read and format these values for DB use

I have updated your example, but since I don't have the tables setup I cannot verify if the updated script even works.

Hope that helps

cheers,
fober

<cfparam name="ID_ROW" default="0">

<cfif isdefined("btn_send")>
<cfloop index="ID_ROW" from="1" to="#form.count#" step="1">
<cfquery datasource="veryvip">
INSERT INTO itransact{
sfiid,
name,
package,
total,
hashinfo}
VALUES(
#dbvalue('sfiid','number')#,
#dbvalue('name','string')#,
#dbvalue('package','number')#,
#dbvalue('total','number')#,
#dbvalue('hashinfo','string')#)
</cfquery>
</cfloop>
<cfabort>
</cfif>

<cfquery datasource="veryvip" name="prepare">
select c.*, i.*
from itransact i, customers c
where i.sfiid=c.sfiid
</cfquery>

<cfform action="index.cfm" method="POST">

<table cellpadding="1" cellspacing="0" border="1" bordercolor="#006699">
<cfoutput query="prepare">
<cfset ID_ROW= ID_ROW +1>
<tr>
<td align="center">
<input type="checkbox" name="#fieldname(mark)#" value="1" checked visible="Yes" enabled="Yes">
</td>
<td><cfinput type="Text" name="#fieldname('sfiid')#" value="#sfiid#" required="Yes" visible="Yes" enabled="Yes" size="5"></td>
<td><cfinput type="Text" name="#fieldname('name')#" value="#firstname# #lastname#" required="No" visible="Yes" enabled="Yes"></td>
<td><cfinput type="Text" name="#fieldname('package')#" value="#package#" validateat="onBlur" validate="integer" required="Yes" visible="Yes" enabled="Yes" size="1"></td>
<td><cfinput type="Text" name="#fieldname('total')#" value="#dollarformat(total)#" required="Yes" visible="Yes" enabled="Yes" size="3"></td>
<td><cfinput type="Text" name="#fieldname('hashinfo')#" value="#hash(sfiid)#:#package#" required="Yes" visible="Yes" enabled="Yes" size="40"></td>
</tr>
</cfoutput>

<tr>
<td> </td>
<td align="center">
<cfinput type="Hidden" name="count" value="#ID_ROW#">
<input type="submit" name="btn_send" value="Send">
</td>
<td colspan="4"> </td>
</tr>
</table>
</cfform>





<!--- ============================================================== --->
<cffunction name="fieldname" output="No">
<cfargument name="field" type="string" default="">

<cfparam name="id_area" default="">
<cfparam name="id_row" default="">

<cfif id_row NEQ "">
<cfset local.field= "#id_row#_#field#">
<cfelse>
<cfset local.field= "#field#">
</cfif>

<cfif id_area NEQ "">
<cfset local.field= "#id_area#_#local.field#">
<cfelseif id_form NEQ "">
<cfset local.field= "#id_form#_#local.field#">
</cfif>
<cfreturn local.field>
</cffunction>

<!--- ============================================================== --->
<cffunction name="fieldvalue" output="No">
<cfargument name="field" type="string" default="">

<cfset local.temp_field= im_fieldname(field)>

<cfif isdefined("#local.temp_field#") IS TRUE>
<cfset local.temp_value= evaluate("#local.temp_field#")>
<cfelse>
<cfset local.temp_value= "">
</cfif>
<cfreturn local.temp_value>
</cffunction>

<!--- ============================================================== --->
<cffunction name="dbvalue" output="No">
<cfargument name="field" type="string" default="">
<cfargument name="type" type="string" default="string">

<cfswitch expression="#type#">
<cfcase value="string">
<cfreturn "'#fieldvalue(field)#'">
</cfcase>
<cfcase value="number">
<cfreturn "'#fieldvalue(field)#'">
</cfcase>
<cfcase value="date">
<cfreturn "'#CreateODBCDate(fieldvalue(field))#'">
</cfcase>
</cfswitch>

<cfset local.temp_field= im_fieldname(field)>

<cfif isdefined("#local.temp_field#") IS TRUE>
<cfset local.temp_value= evaluate("#local.temp_field#")>
<cfelse>
<cfset local.temp_value= "">
</cfif>
<cfreturn local.temp_value>
</cffunction>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation