Extracts keys from a ColdFusion structure.
A list of keys; if structure does not exist, ColdFusion throws an exception.
StructKeyList(structure
[,delimiter
])
Structure functions; "Modifying a ColdFusion XML object" in the ColdFusion Developer's Guide
Parameter |
Description |
---|---|
structure |
Structure from which to extract a list of keys. |
delimiter |
Optional. Character that separates keys in list. The default value is comma. |
A structure's keys are unordered.
<!--- This example shows how to use StructKeyList to list the keys in a structure. It uses StructNew function to create structure and fills it with information user enters in form fields. ---> <!--- This section creates structure and checks whether Submit has been pressed. If so, code defines fields in the employee structure with what the user entered in the form. ---> <cfset employee = StructNew()> <cfif Isdefined("Form.Submit")> <cfif Form.Submit is "OK"> <cfset employee.firstname = FORM.firstname> <cfset employee.lastname = FORM.lastname> <cfset employee.email = FORM.email> <cfset employee.phone = FORM.phone> <cfset employee.company = FORM.company> <cfelseIf Form.Submit is "Clear"> <cfset rc = StructClear(employee)> </cfif> </cfif> <html> <head> <title>StructKeyList Function</title> </head> <body> <h3>StructKeyList Function</h3> <h3>Listing the Keys in the Employees Structure</h3> <p>This example uses StructNew function to create structure "employee" that supplies employee information. The fields are filled with the contents of the following form.</p> <p>After you enter employee information into structure, example uses <b>StructKeyList</b> function to list keys in structure.</p> <p>This code does not show how to insert information into a database. See cfquery for more information about database insertion. <hr size = "2" color = "#0000A0"> <form action = "structkeylist.cfm"> <table cellspacing = "2" cellpadding = "2" border = "0"> <tr> <td>First Name:</td> <td><input name = "firstname" type = "text" value = "" hspace = "30" maxlength = "30"></td> </tr> <tr> <td>Last Name:</td> <td><input name = "lastname" type = "text" value = "" hspace = "30" maxlength = "30"></td> </tr> <tr> <td>EMail</td> <td><input name = "email" type = "text" value = "" hspace = "30" maxlength = "30"></td> </tr> <tr> <td>Phone:</td> <td><input name = "phone" type = "text" value = "" hspace = "20" maxlength = "20"></td> </tr> <tr> <td>Company:</td> <td><input name = "company" type = "text" value = "" hspace = "30" maxlength = "30"></td> </tr> <tr> <td><input type = "submit" name = "submit" value = "OK"></td> <td><b>After you submit form, scroll down to see the list.</b></td> </tr> </table> </form> <cfif NOT StructISEmpty(employee)> <hr size = "2" color = "#0000A0"> <cfset keysToStruct = StructKeyList(employee,"<li>")> <p>Here are the keys to the structure:</p> <ul> <li> <cfoutput>#keysToStruct#</cfoutput> </ul> <p>If fields are correct, we can process new employee information. If they are not correct, consider rewriting application.</p> </cfif>