home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Documentation / snippets / structkeylist.cfm < prev    next >
Encoding:
Text File  |  1999-04-12  |  3.0 KB  |  98 lines

  1. <!--- This example shows how to use the StructKeyList
  2.       function to list the keys within a specified structure.
  3.       It also uses the StructNew function to create the structure
  4.       and fills its fields with the information the user types 
  5.       into the corresponding form fields. --->
  6.       
  7. <!--- This section of code creates the new structure and checks to 
  8.       see if the submit button has been pressed.  If it has been
  9.       pressed, the code defines fields in the employee structure
  10.       with what the user has entered from the form. --->
  11. <CFSET employee=StructNew()>  
  12. <CFIF Isdefined("Form.Submit")>
  13.     <CFIF Form.Submit is "OK">
  14.         <CFSET employee.firstname = FORM.firstname>
  15.         <CFSET employee.lastname = FORM.lastname>
  16.         <CFSET employee.email = FORM.email>
  17.         <CFSET employee.phone = FORM.phone>
  18.         <CFSET employee.company = FORM.company> 
  19.     <CFELSEIF Form.Submit is "Clear">
  20.         <CFSET rc=StructClear(employee)>
  21.     </CFIF>
  22. </CFIF>      
  23.       
  24.  
  25.       
  26. <HTML>
  27. <HEAD>
  28. <title>StructKeyList Function</title>
  29. </HEAD>
  30.  
  31. <BASEFONT FACE="Arial, Helvetica" SIZE=2>
  32.  
  33. <BODY  bgcolor="#FFFFD5">
  34.  
  35. <H3>StructKeyList Function</H3>
  36. <H3>Listing the Keys in the Employees Structure</H3>
  37. <P>
  38. This example uses the StructNew function to create a structure 
  39. that supplies employee information.  The data structure is called 
  40. "employee" and its fields are filled with the contents of the following form.
  41. After you have entered employee information into the structure, the example uses 
  42. the <b>StructKeyList</b> function to list all of the keys in the structure.
  43. This code does not show how to
  44. insert this information into a database.  See CFQUERY for more information
  45. about database insertion.
  46.  
  47. <HR size="2" color="#0000A0">
  48. <FORM action="structkeylist.cfm" method="post">
  49. <table cellspacing="2" cellpadding="2" border="0">
  50.     <tr>
  51.     <td>First Name:</td>
  52.     <td><INPUT name="firstname" type="text" value="" hspace="30" maxlength="30"></td>
  53.     </tr>
  54.     <tr>
  55.     <td>Last Name:</td>
  56.     <td><INPUT name="lastname" type="text" value="" hspace="30" maxlength="30"></td>
  57.     </tr>
  58.     <tr>
  59.     <td>EMail</td>
  60.     <td><INPUT name="email" type="text" value="" hspace="30" maxlength="30"></td>
  61.     </tr>
  62.     <tr>
  63.     <td>Phone:</td>
  64.     <td><INPUT name="phone" type="text" value="" hspace="20" maxlength="20"></td>
  65.     </tr>
  66.     <tr>
  67.     <td>Company:</td>
  68.     <td><INPUT name="company" type="text" value="" hspace="30" maxlength="30"></td>
  69.     </tr>
  70.     <tr>
  71.     <td><input type="submit" name="submit" value="OK"></td>
  72.     <td><b>After you submit the form, scroll down to see the list.</b></td>
  73.     </tr>
  74. </table>
  75. </FORM>
  76.  
  77.  
  78.  
  79. <CFIF NOT StructISEmpty(employee)> 
  80.     <HR size="2" color="#0000A0"> 
  81.     <CFSET keysToStruct = StructKeyList(employee,"<LI>")>
  82.     <P>Here are the keys to the structure:</P> 
  83.     <UL>
  84.     <LI>
  85.     <CFOUTPUT>#keysToStruct#</CFOUTPUT>
  86.     </UL>
  87.  
  88.     <P>    
  89.      If these fields are correct, we can process your new employee information. 
  90.      If they are not correct, you should consider rewriting your application.
  91.     </P>
  92.  
  93. </CFIF>
  94.  
  95.  
  96. </BODY>
  97. </HTML>
  98.