Solved

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

Posted on 2001-07-10
2
275 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
[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
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

724 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