问题
I'm trying to parse a string into two variables. The source is a SQL query that populates values for multiple checkboxes. The number of checkboxes varies base on the query results. The checkboxes are coded:
<input type="checkbox" name="Listname" value="#RecID#:#DistListName#" ID="ListName#ListID#">
Using code I found here, I remove the :
separating RecID and DistListName with:
<cfset PreParseList = #form.Listname#>
<cfset ParseList = ListToArray(PreParseList, ":", false, true)>
The output of ParseList looks like this:
627 Corporate IT Desktop Team DL,629 Corporate IT Helpdesk Team DL,607 HMC Behavioral Health DL,257 Kauai Region HR
I need to create two variables, one for the RECID which can be 1 to 3 digits long, and one for the name. The RecID gets written to a junction table that controls what distribution lists a user would have access to. The name is just displayed on the confirmation page.
Is what I'm trying even possible, or should I look into a different way of passing the RecID and name?
回答1:
<cfset recIds = []>
<cfset distListNames = []>
<cfloop list="#form.Listname#" index="checkboxValue">
<cfset arrayAppend(recIds, listFirst(checkboxValue, ':'))>
<cfset arrayAppend(distListNames, ListRest(checkboxValue, ':'))>
</cfloop>
should I look into a different way of passing the RecID and name?
It'd be logical to only set the value of checkbox to RecID, since "the name is just displayed on the confirmation page". Then you get a list of RecIDs
from the form
scope, ready to be used, for free. Is the confirmation page a CFM page? If so, couldn't you display the name(s) that by fetching from DB again by ID(s)?
来源:https://stackoverflow.com/questions/29996631/create-two-variables-from-parsed-string