| 1 |
<!DOCTYPE html> |
| 2 |
<html><head> |
| 3 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> |
| 4 |
<title>highlight.cfml</title> |
| 5 |
<meta name="generator" content="KF5::SyntaxHighlighting - Definition (ColdFusion) - Theme (Breeze Light)"/> |
| 6 |
</head><body style="background-color:#ffffff;color:#1f1c1b"><pre> |
| 7 |
<span style="color:#898887;"><!--- ColdFusion Sample File ---></span> |
| 8 |
<span style="color:#898887;"><!--- Source: https://helpx.adobe.com/coldfusion/developing-applications/the-cfml-programming-language/using-arrays-and-structures/structure-examples.html ---></span> |
| 9 |
|
| 10 |
<span style="font-weight:bold;"><head></span> |
| 11 |
<span style="font-weight:bold;"><title></span>Add New Employees<span style="font-weight:bold;"></title></span> |
| 12 |
<span style="font-weight:bold;"></head></span> |
| 13 |
|
| 14 |
<span style="font-weight:bold;"><body></span> |
| 15 |
<span style="font-weight:bold;"><h1></span>Add New Employees<span style="font-weight:bold;"></h1></span> |
| 16 |
<span style="color:#898887;"><!--- Action page code for the form at the bottom of this page. ---></span> |
| 17 |
|
| 18 |
<span style="color:#898887;"><!--- Establish parameters for first time through ---></span> |
| 19 |
<span style="color:#644a9b;font-weight:bold;"><cfparam</span><span style="color:#006e28;"> name</span>=<span style="color:#bf0303;">"Form.firstname"</span><span style="color:#006e28;"> default</span>=<span style="color:#bf0303;">""</span><span style="color:#644a9b;font-weight:bold;">></span> |
| 20 |
<span style="color:#644a9b;font-weight:bold;"><cfparam</span><span style="color:#006e28;"> name</span>=<span style="color:#bf0303;">"Form.lastname"</span><span style="color:#006e28;"> default</span>=<span style="color:#bf0303;">""</span><span style="color:#644a9b;font-weight:bold;">></span> |
| 21 |
<span style="color:#644a9b;font-weight:bold;"><cfparam</span><span style="color:#006e28;"> name</span>=<span style="color:#bf0303;">"Form.email"</span><span style="color:#006e28;"> default</span>=<span style="color:#bf0303;">""</span><span style="color:#644a9b;font-weight:bold;">></span> |
| 22 |
<span style="color:#644a9b;font-weight:bold;"><cfparam</span><span style="color:#006e28;"> name</span>=<span style="color:#bf0303;">"Form.phone"</span><span style="color:#006e28;"> default</span>=<span style="color:#bf0303;">""</span><span style="color:#644a9b;font-weight:bold;">></span> |
| 23 |
<span style="color:#644a9b;font-weight:bold;"><cfparam</span><span style="color:#006e28;"> name</span>=<span style="color:#bf0303;">"Form.department"</span><span style="color:#006e28;"> default</span>=<span style="color:#bf0303;">""</span><span style="color:#644a9b;font-weight:bold;">></span> |
| 24 |
|
| 25 |
<span style="color:#898887;"><!--- If at least the firstname form field is passed, create</span> |
| 26 |
<span style="color:#898887;">a structure named employee and add values. ---></span> |
| 27 |
<span style="color:#644a9b;font-weight:bold;"><cfif #Form.firstname# eq </span><span style="color:#bf0303;">""</span><span style="color:#644a9b;font-weight:bold;">></span> |
| 28 |
<span style="font-weight:bold;"><p></span>Please fill out the form.<span style="font-weight:bold;"></p></span> |
| 29 |
<span style="color:#644a9b;font-weight:bold;"><cfelse></span> |
| 30 |
<span style="color:#644a9b;font-weight:bold;"><cfoutput></span> |
| 31 |
<span style="color:#bf0303;font-weight:bold;"><cfscript></span> |
| 32 |
employee<span style="font-weight:bold;">=</span><span style="color:#644a9b;font-weight:bold;">StructNew</span><span style="font-weight:bold;">()</span>; |
| 33 |
employee.firstname <span style="font-weight:bold;">=</span> Form.firstname; |
| 34 |
employee.lastname <span style="font-weight:bold;">=</span> Form.lastname; |
| 35 |
employee.email <span style="font-weight:bold;">=</span> Form.email; |
| 36 |
employee.phone <span style="font-weight:bold;">=</span> Form.phone; |
| 37 |
employee.department <span style="font-weight:bold;">=</span> Form.department; |
| 38 |
<span style="color:#bf0303;font-weight:bold;"></cfscript></span> |
| 39 |
|
| 40 |
<span style="color:#898887;"><!--- Display results of creating the structure. ---></span> |
| 41 |
First name is #StructFind(employee, "firstname")#<span style="font-weight:bold;"><br></span> |
| 42 |
Last name is #StructFind(employee, "lastname")#<span style="font-weight:bold;"><br></span> |
| 43 |
EMail is #StructFind(employee, "email")#<span style="font-weight:bold;"><br></span> |
| 44 |
Phone is #StructFind(employee, "phone")#<span style="font-weight:bold;"><br></span> |
| 45 |
Department is #StructFind(employee, "department")#<span style="font-weight:bold;"><br></span> |
| 46 |
<span style="color:#644a9b;font-weight:bold;"></cfoutput></span> |
| 47 |
|
| 48 |
<span style="color:#898887;"><!--- Call the custom tag that adds employees. ---></span> |
| 49 |
<span style="color:#0057ae;font-weight:bold;"><cf_addemployee</span><span style="color:#006e28;"> empinfo</span>=<span style="color:#bf0303;">"#employee#"</span><span style="color:#0057ae;font-weight:bold;">></span> |
| 50 |
<span style="color:#644a9b;font-weight:bold;"></cfif></span> |
| 51 |
|
| 52 |
<span style="color:#898887;"><!--- The form for adding the new employee information ---></span> |
| 53 |
<span style="font-weight:bold;"><hr></span> |
| 54 |
<span style="font-weight:bold;"><form</span><span style="color:#006e28;"> action</span>=<span style="color:#bf0303;">"newemployee.cfm"</span><span style="color:#006e28;"> method</span>=<span style="color:#bf0303;">"Post"</span><span style="font-weight:bold;">></span> |
| 55 |
First Name:<span style="color:#b08000;">&nbsp;</span> |
| 56 |
<span style="font-weight:bold;"><input</span><span style="color:#006e28;"> name</span>=<span style="color:#bf0303;">"firstname"</span><span style="color:#006e28;"> type</span>=<span style="color:#bf0303;">"text"</span><span style="color:#006e28;"> hspace</span>=<span style="color:#bf0303;">"30"</span><span style="color:#006e28;"> maxlength</span>=<span style="color:#bf0303;">"30"</span><span style="font-weight:bold;">><br></span> |
| 57 |
Last Name:<span style="color:#b08000;">&nbsp;</span> |
| 58 |
<span style="font-weight:bold;"><input</span><span style="color:#006e28;"> name</span>=<span style="color:#bf0303;">"lastname"</span><span style="color:#006e28;"> type</span>=<span style="color:#bf0303;">"text"</span><span style="color:#006e28;"> hspace</span>=<span style="color:#bf0303;">"30"</span><span style="color:#006e28;"> maxlength</span>=<span style="color:#bf0303;">"30"</span><span style="font-weight:bold;">><br></span> |
| 59 |
EMail:<span style="color:#b08000;">&nbsp;</span> |
| 60 |
<span style="font-weight:bold;"><input</span><span style="color:#006e28;"> name</span>=<span style="color:#bf0303;">"email"</span><span style="color:#006e28;"> type</span>=<span style="color:#bf0303;">"text"</span><span style="color:#006e28;"> hspace</span>=<span style="color:#bf0303;">"30"</span><span style="color:#006e28;"> maxlength</span>=<span style="color:#bf0303;">"30"</span><span style="font-weight:bold;">><br></span> |
| 61 |
Phone:<span style="color:#b08000;">&nbsp;</span> |
| 62 |
<span style="font-weight:bold;"><input</span><span style="color:#006e28;"> name</span>=<span style="color:#bf0303;">"phone"</span><span style="color:#006e28;"> type</span>=<span style="color:#bf0303;">"text"</span><span style="color:#006e28;"> hspace</span>=<span style="color:#bf0303;">"20"</span><span style="color:#006e28;"> maxlength</span>=<span style="color:#bf0303;">"20"</span><span style="font-weight:bold;">><br></span> |
| 63 |
Department:<span style="color:#b08000;">&nbsp;</span> |
| 64 |
<span style="font-weight:bold;"><input</span><span style="color:#006e28;"> name</span>=<span style="color:#bf0303;">"department"</span><span style="color:#006e28;"> type</span>=<span style="color:#bf0303;">"text"</span><span style="color:#006e28;"> hspace</span>=<span style="color:#bf0303;">"30"</span><span style="color:#006e28;"> maxlength</span>=<span style="color:#bf0303;">"30"</span><span style="font-weight:bold;">><br></span> |
| 65 |
|
| 66 |
<span style="font-weight:bold;"><input</span><span style="color:#006e28;"> type</span>=<span style="color:#bf0303;">"Submit"</span><span style="color:#006e28;"> value</span>=<span style="color:#bf0303;">"OK"</span><span style="font-weight:bold;">></span> |
| 67 |
<span style="font-weight:bold;"></form></span> |
| 68 |
<span style="font-weight:bold;"><br></span> |
| 69 |
<span style="font-weight:bold;"></body></span> |
| 70 |
<span style="font-weight:bold;"></html></span> |
| 71 |
|
| 72 |
<span style="color:#644a9b;font-weight:bold;"><cfoutput></span> |
| 73 |
Error. No employee data was passed.<span style="font-weight:bold;"><br></span> |
| 74 |
<span style="color:#644a9b;font-weight:bold;"></cfoutput></span> |
| 75 |
<span style="color:#644a9b;font-weight:bold;"><cfexit</span><span style="color:#006e28;"> method</span>=<span style="color:#bf0303;">"ExitTag"</span><span style="color:#644a9b;font-weight:bold;">></span> |
| 76 |
<span style="color:#644a9b;font-weight:bold;"><cfelse></span> |
| 77 |
<span style="color:#898887;"><!--- Add the employee ---></span> |
| 78 |
<span style="color:#644a9b;font-weight:bold;"><cfquery</span><span style="color:#006e28;"> name</span>=<span style="color:#bf0303;">"AddEmployee"</span><span style="color:#006e28;"> datasource</span>=<span style="color:#bf0303;">"cfdocexamples"</span><span style="color:#644a9b;font-weight:bold;">></span> |
| 79 |
INSERT INTO Employees |
| 80 |
(FirstName, LastName, Email, Phone, Department) |
| 81 |
VALUES ( |
| 82 |
'#attributes.empinfo.firstname#' , |
| 83 |
'#attributes.empinfo.lastname#' , |
| 84 |
'#attributes.empinfo.email#' , |
| 85 |
'#attributes.empinfo.phone#' , |
| 86 |
'#attributes.empinfo.department#' ) |
| 87 |
<span style="color:#644a9b;font-weight:bold;"></cfquery></span> |
| 88 |
<span style="color:#644a9b;font-weight:bold;"></cfif></span> |
| 89 |
<span style="color:#644a9b;font-weight:bold;"><cfoutput></span> |
| 90 |
<span style="font-weight:bold;"><hr></span>Employee Add Complete |
| 91 |
<span style="color:#644a9b;font-weight:bold;"></cfoutput></span> |
| 92 |
|
| 93 |
<span style="color:#898887;"><!--- temperature.cfc ---></span> |
| 94 |
<span style="color:#644a9b;font-weight:bold;"><cfcomponent></span> |
| 95 |
<span style="color:#644a9b;font-weight:bold;"><cffunction</span><span style="color:#006e28;"> name</span>=<span style="color:#bf0303;">"FtoC"</span><span style="color:#006e28;"> access</span>=<span style="color:#bf0303;">"public"</span><span style="color:#006e28;"> returntype</span>=<span style="color:#bf0303;">"numeric"</span><span style="color:#644a9b;font-weight:bold;">></span> |
| 96 |
<span style="color:#644a9b;font-weight:bold;"><cfargument</span><span style="color:#006e28;"> name</span>=<span style="color:#bf0303;">"fahrenheit"</span><span style="color:#006e28;"> required</span>=<span style="color:#bf0303;">"yes"</span><span style="color:#006e28;"> type</span>=<span style="color:#bf0303;">"numeric"</span><span style="color:#644a9b;font-weight:bold;"> /></span> |
| 97 |
<span style="color:#644a9b;font-weight:bold;"><cfset</span><span style="color:#006e28;"> answer</span>=<span style="color:#644a9b;font-weight:bold;"> (fahrenheit - 32)*100/180 /></span> |
| 98 |
<span style="color:#644a9b;font-weight:bold;"><cfreturn answer /></span> |
| 99 |
<span style="color:#644a9b;font-weight:bold;"></cffunction></span> |
| 100 |
<span style="color:#644a9b;font-weight:bold;"></cfcomponent></span> |
| 101 |
<span style="color:#898887;"><!--- test.cfm ---></span> |
| 102 |
<span style="color:#644a9b;font-weight:bold;"><cfset</span><span style="color:#006e28;"> fDegrees</span><span style="color:#644a9b;font-weight:bold;"> </span>=<span style="color:#644a9b;font-weight:bold;"> 212 /></span> |
| 103 |
<span style="color:#644a9b;font-weight:bold;"><cfinvoke</span><span style="color:#006e28;"> component</span>=<span style="color:#bf0303;">"temperature"</span><span style="color:#006e28;"> method</span>=<span style="color:#bf0303;">"FtoC"</span><span style="color:#006e28;"> returnvariable</span>=<span style="color:#bf0303;">"result"</span><span style="color:#644a9b;font-weight:bold;">></span> |
| 104 |
<span style="color:#644a9b;font-weight:bold;"><cfinvokeargument</span><span style="color:#006e28;"> name</span>=<span style="color:#bf0303;">"fahrenheit"</span><span style="color:#006e28;"> value</span>=<span style="color:#bf0303;">"#fDegrees#"</span><span style="color:#644a9b;font-weight:bold;"> /></span> |
| 105 |
<span style="color:#644a9b;font-weight:bold;"></cfinvoke></span> |
| 106 |
<span style="color:#644a9b;font-weight:bold;"><cfoutput></span>#fDegrees#<span style="color:#b08000;">&deg;</span>F = #result#<span style="color:#b08000;">&deg;</span>C<span style="color:#644a9b;font-weight:bold;"></cfoutput></span> <span style="font-weight:bold;"><br /></span> |
| 107 |
|
| 108 |
<span style="color:#644a9b;font-weight:bold;"><cfset</span><span style="color:#006e28;"> person</span><span style="color:#644a9b;font-weight:bold;"> </span>=<span style="color:#644a9b;font-weight:bold;"> CreateObject(</span><span style="color:#bf0303;">"component"</span><span style="color:#644a9b;font-weight:bold;">, </span><span style="color:#bf0303;">"Person"</span><span style="color:#644a9b;font-weight:bold;">) /></span> |
| 109 |
</pre></body></html> |