Solved

Passing dynamically named checkbox values to an appended list (spectra/CF)

Posted on 2001-07-10
2
263 Views
Last Modified: 2013-12-24
I don't know how difficult this question is to answer, but it's worth a lot to me: 200 points!

I created about fifty dynamically named checkboxes by looping through a set of objects and naming each checkbox with the objectID in the structure of each object. (I'm actually using Spectra objects here, but essentially I think this would be the same as straight CF)

When I submit the form, I want to take the ObjectIDs which come from the checked checkboxes and use listAppend() to create a comma-delimited list. I'll then insert the list into a property of an object I'm trying to update.

My code breaks down when I try to make the list. After I submit the form, I believe I have to loop through the same set of objects to recreate the names of the checkboxes and see if they were checked when submitted.

I thought that normally with checkboxes, if the box is checked when submitted then form.formfield for that checkbox would evaluate as "on" and if it is empty when submitted, it would evaluate as "off". But if I try to say <cfif form.Product[ct].objectID eq "on"> then append the ID to the list, it never works because form.product[ct].objectid always evaluates to "form.74DB80CD-593B-11D5-9C440090277322BD" or whatever the ID of the current object is.

Here is my most recent rendition of my code (note that I get the content from a Spectra content-object database):

<!--- Get all the product Overviews to populate checkbox form items and make "productList" list--->
      <cfa_contentObjectGetMultiple
            dataSource = "#prgn_corp_db#"
               typeID = "#tpsProductOverview#"
               r_stObjects = "stProducts"
                >

      
       <cfa_structSortCommonSubkeys
                struct = "#stProducts#"
                commonSubKey = "psSortOrder"
            sortType = "numeric"
                sortOrder = "asc"
                r_aSortedKeys = "productKey"
            >      

<cfif isdefined("form.ApplyChanges")>

<!--- Establish ObjectID to update from Hidden Form Field --->
      <cfset url.objectid ="#form.objectid#">

<!--- Create list of Product UUIDs from selected form checkbox items. --->

<cfset productList = "">
      
<cfloop list=#arraytolist(productKey)# index="ctX">
      <cfset productUUID = replace(stProducts[ctx].objectid, "-", "_", "all")>
<!--- This is the problem! --->
      <cfif isDefined(evaluate(de('form.' & productUUID)))>
      <cfset productList = listAppend(productList, stProducts[ctx].objectID)>
      </cfif>
<!--- This is seemingly the end of my problem - my list is empty --->
      
</cfloop>       

<!--- update the content object property --->

<cfa_contentObjectData
        dataSource = "#prgn_corp_db#"
      ISOLanguage="en"
      objectID = "#form.objectid#"
      >
     
      <cfa_contentObjectProperty
      name="psAssociatedProducts"
      value="#productList#"
      >

</cfa_contentObjectData>


            
<cfif>

<!--- Read the Staged Object to which you want to add the list of Product UUIDs --->
   <cfa_contentObjectGet
      datasource = "#prgn_corp_db#"
      objectid = "#url.objectid#"
      r_stObject = "stProfile"
      >

<cfform name="Partnersform" action="pstPRGNPartnersEditOne.cfm?myaction=#URLEncodedFormat(myAction)#&typeid=#URLEncodedFormat(url.typeid)#" method="post">
<input type="hidden"  name="query_string" value="#cgi.query_string#">
<input type="hidden"  name="objectid" value="#url.objectid#">      

<!--- display checkboxes of all possible products that stProfile can be associated with --->
<table border="0" cellpadding="3" cellspacing="4" width="99%">

      <cfloop list="#arraytolist(productKey)#" index="ct">
      <tr>

      <td>
            <!--- replace all ID hyphens with underscores --->
          <cfset productUUID = replace(stProducts[ct].objectID, "-", "_", "all")>
            <cfif structKeyExists(stProfile.psAssociatedProducts, "#mylanguage#") and stProfile.psAssociatedProducts[mylanguage] contains "#stProducts[ct].objectID#">
            <cfinput type="Checkbox" name="#productUUID#" checked>
            <cfelse>
            <cfinput type="Checkbox" name="#productUUID#">
            </cfif>
      <font size="-3">#stProducts[ct].psProductTitle#</font>
      </td>
      
      </tr>
</cfloop>

</table>
<hr>
<input type="submit" NAME="ApplyChanges" value="Stage">  
</cfform>


0
Comment
Question by:KateDeJong
2 Comments
 
LVL 1

Accepted Solution

by:
Drewbytes earned 200 total points
ID: 6272513
The problem is with your checkboxes.

Each checkbox has to have the same name, but you set the value as the productuuid, you then get all the ticked checkboxes upon submit (all unchecked ones are not passed) as a comma delimited list of the uuid values you want.

This small example shows a working example.

<cfif isdefined("form.submited")>
     value = <cfoutput>#form.test#</cfoutput>
     <cfabort>
</cfif>

<form action="index.cfm" method="post">
     <input type="checkbox" name="test" value="123">
     <input type="checkbox" name="test" value="456">
     <input type="checkbox" name="test" value="789">
     <input type=submit name="submited" value="go">
</form>
0
 

Author Comment

by:KateDeJong
ID: 6273358
Thanks for your help! I knew radio buttons needed the same name, but I thought checkboxes were separate entities!

I spent a long time trying to come up with a "complex" CF solution, and now it's been fixed in a matter of minutes.

-Kate
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
php.ini on ipage hosting 12 41
Problem to Eclipse 16 101
JKS to store upstart data 2 66
cookies analysis tools 2 27
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 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