Returns the list of keys in a ColdFusion structure.
StructKeyList(structure, [delimiter])
StructClear, StructDelete, StructFind, StructInsert, StructIsEmpty, StructKeyArray, StructCount, StructNew, StructUpdate, StructAppend, StructGet, StructSort, StructFindKey, StructClear
| Parameter |
Description |
|---|---|
| structure |
Structure from which to extract a list of keys |
| delimiter |
Optional. Character that separates the keys in the list. By default, a comma is used. |
The list of keys returned by StructKeyList is not in any particular order. To sort keys alphabetically or numerically, use ListSort.
This function throws an exception if structure does not exist.
<!--- This example shows how to use the StructKeyList
function to list the keys within a specified structure.
It also uses the StructNew function to create the structure
and fills its fields with the information the user types
into the corresponding form fields. --->
<!--- This section of code creates the new structure and checks to
see if the submit button has been pressed. If it has been
pressed, the code defines fields in the employee structure
with what the user has entered from 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>
<basefont face = "Arial, Helvetica" size = 2>
<body bgcolor = "#FFFFD5">
<H3>StructKeyList Function</H3>
<H3>Listing the Keys in the Employees Structure</H3>
<P>
This example uses the StructNew function to create a structure
that supplies employee information. The data structure is called
"employee" and its fields are filled with the contents of the
following form.
</P>
<P>
After you have entered employee information into the structure,
the example uses the <b>StructKeyList</b> function to list all
of the keys in the structure.
</P>
<P>
This code does not show how to insert this information into a
database. See cfquery for more information about database insertion.
<hr size = "2" color = "#0000A0">
<form action = "structkeylist.cfm" method = "post">
<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 the 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 these fields are correct, we can process your new employee
information. If they are not correct, you should consider rewriting
your application.
</P>
</cfif>
</body>
</html>