Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2001-07-10
2
Medium Priority
?
284 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 800 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

Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

Question has a verified solution.

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

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
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 …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

597 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