| 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 Dark)"/> |
| 6 |
</head><body style="background-color:#232629;color:#cfcfc2"><pre> |
| 7 |
<span style="color:#7a7c7d;"><!--- ColdFusion Sample File ---></span> |
| 8 |
<span style="color:#7a7c7d;"><!--- 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:#7a7c7d;"><!--- Action page code for the form at the bottom of this page. ---></span> |
| 17 |
|
| 18 |
<span style="color:#7a7c7d;"><!--- Establish parameters for first time through ---></span> |
| 19 |
<span style="color:#8e44ad;font-weight:bold;"><cfparam</span><span style="color:#27ae60;"> name</span>=<span style="color:#f44f4f;">"Form.firstname"</span><span style="color:#27ae60;"> default</span>=<span style="color:#f44f4f;">""</span><span style="color:#8e44ad;font-weight:bold;">></span> |
| 20 |
<span style="color:#8e44ad;font-weight:bold;"><cfparam</span><span style="color:#27ae60;"> name</span>=<span style="color:#f44f4f;">"Form.lastname"</span><span style="color:#27ae60;"> default</span>=<span style="color:#f44f4f;">""</span><span style="color:#8e44ad;font-weight:bold;">></span> |
| 21 |
<span style="color:#8e44ad;font-weight:bold;"><cfparam</span><span style="color:#27ae60;"> name</span>=<span style="color:#f44f4f;">"Form.email"</span><span style="color:#27ae60;"> default</span>=<span style="color:#f44f4f;">""</span><span style="color:#8e44ad;font-weight:bold;">></span> |
| 22 |
<span style="color:#8e44ad;font-weight:bold;"><cfparam</span><span style="color:#27ae60;"> name</span>=<span style="color:#f44f4f;">"Form.phone"</span><span style="color:#27ae60;"> default</span>=<span style="color:#f44f4f;">""</span><span style="color:#8e44ad;font-weight:bold;">></span> |
| 23 |
<span style="color:#8e44ad;font-weight:bold;"><cfparam</span><span style="color:#27ae60;"> name</span>=<span style="color:#f44f4f;">"Form.department"</span><span style="color:#27ae60;"> default</span>=<span style="color:#f44f4f;">""</span><span style="color:#8e44ad;font-weight:bold;">></span> |
| 24 |
|
| 25 |
<span style="color:#7a7c7d;"><!--- If at least the firstname form field is passed, create</span> |
| 26 |
<span style="color:#7a7c7d;">a structure named employee and add values. ---></span> |
| 27 |
<span style="color:#8e44ad;font-weight:bold;"><cfif #Form.firstname# eq </span><span style="color:#f44f4f;">""</span><span style="color:#8e44ad;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:#8e44ad;font-weight:bold;"><cfelse></span> |
| 30 |
<span style="color:#8e44ad;font-weight:bold;"><cfoutput></span> |
| 31 |
<span style="color:#da4453;font-weight:bold;"><cfscript></span> |
| 32 |
employee<span style="font-weight:bold;">=</span><span style="color:#8e44ad;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:#da4453;font-weight:bold;"></cfscript></span> |
| 39 |
|
| 40 |
<span style="color:#7a7c7d;"><!--- 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:#8e44ad;font-weight:bold;"></cfoutput></span> |
| 47 |
|
| 48 |
<span style="color:#7a7c7d;"><!--- Call the custom tag that adds employees. ---></span> |
| 49 |
<span style="color:#2980b9;font-weight:bold;"><cf_addemployee</span><span style="color:#27ae60;"> empinfo</span>=<span style="color:#f44f4f;">"#employee#"</span><span style="color:#2980b9;font-weight:bold;">></span> |
| 50 |
<span style="color:#8e44ad;font-weight:bold;"></cfif></span> |
| 51 |
|
| 52 |
<span style="color:#7a7c7d;"><!--- 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:#27ae60;"> action</span>=<span style="color:#f44f4f;">"newemployee.cfm"</span><span style="color:#27ae60;"> method</span>=<span style="color:#f44f4f;">"Post"</span><span style="font-weight:bold;">></span> |
| 55 |
First Name:<span style="color:#c45b00;">&nbsp;</span> |
| 56 |
<span style="font-weight:bold;"><input</span><span style="color:#27ae60;"> name</span>=<span style="color:#f44f4f;">"firstname"</span><span style="color:#27ae60;"> type</span>=<span style="color:#f44f4f;">"text"</span><span style="color:#27ae60;"> hspace</span>=<span style="color:#f44f4f;">"30"</span><span style="color:#27ae60;"> maxlength</span>=<span style="color:#f44f4f;">"30"</span><span style="font-weight:bold;">><br></span> |
| 57 |
Last Name:<span style="color:#c45b00;">&nbsp;</span> |
| 58 |
<span style="font-weight:bold;"><input</span><span style="color:#27ae60;"> name</span>=<span style="color:#f44f4f;">"lastname"</span><span style="color:#27ae60;"> type</span>=<span style="color:#f44f4f;">"text"</span><span style="color:#27ae60;"> hspace</span>=<span style="color:#f44f4f;">"30"</span><span style="color:#27ae60;"> maxlength</span>=<span style="color:#f44f4f;">"30"</span><span style="font-weight:bold;">><br></span> |
| 59 |
EMail:<span style="color:#c45b00;">&nbsp;</span> |
| 60 |
<span style="font-weight:bold;"><input</span><span style="color:#27ae60;"> name</span>=<span style="color:#f44f4f;">"email"</span><span style="color:#27ae60;"> type</span>=<span style="color:#f44f4f;">"text"</span><span style="color:#27ae60;"> hspace</span>=<span style="color:#f44f4f;">"30"</span><span style="color:#27ae60;"> maxlength</span>=<span style="color:#f44f4f;">"30"</span><span style="font-weight:bold;">><br></span> |
| 61 |
Phone:<span style="color:#c45b00;">&nbsp;</span> |
| 62 |
<span style="font-weight:bold;"><input</span><span style="color:#27ae60;"> name</span>=<span style="color:#f44f4f;">"phone"</span><span style="color:#27ae60;"> type</span>=<span style="color:#f44f4f;">"text"</span><span style="color:#27ae60;"> hspace</span>=<span style="color:#f44f4f;">"20"</span><span style="color:#27ae60;"> maxlength</span>=<span style="color:#f44f4f;">"20"</span><span style="font-weight:bold;">><br></span> |
| 63 |
Department:<span style="color:#c45b00;">&nbsp;</span> |
| 64 |
<span style="font-weight:bold;"><input</span><span style="color:#27ae60;"> name</span>=<span style="color:#f44f4f;">"department"</span><span style="color:#27ae60;"> type</span>=<span style="color:#f44f4f;">"text"</span><span style="color:#27ae60;"> hspace</span>=<span style="color:#f44f4f;">"30"</span><span style="color:#27ae60;"> maxlength</span>=<span style="color:#f44f4f;">"30"</span><span style="font-weight:bold;">><br></span> |
| 65 |
|
| 66 |
<span style="font-weight:bold;"><input</span><span style="color:#27ae60;"> type</span>=<span style="color:#f44f4f;">"Submit"</span><span style="color:#27ae60;"> value</span>=<span style="color:#f44f4f;">"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:#8e44ad;font-weight:bold;"><cfoutput></span> |
| 73 |
Error. No employee data was passed.<span style="font-weight:bold;"><br></span> |
| 74 |
<span style="color:#8e44ad;font-weight:bold;"></cfoutput></span> |
| 75 |
<span style="color:#8e44ad;font-weight:bold;"><cfexit</span><span style="color:#27ae60;"> method</span>=<span style="color:#f44f4f;">"ExitTag"</span><span style="color:#8e44ad;font-weight:bold;">></span> |
| 76 |
<span style="color:#8e44ad;font-weight:bold;"><cfelse></span> |
| 77 |
<span style="color:#7a7c7d;"><!--- Add the employee ---></span> |
| 78 |
<span style="color:#8e44ad;font-weight:bold;"><cfquery</span><span style="color:#27ae60;"> name</span>=<span style="color:#f44f4f;">"AddEmployee"</span><span style="color:#27ae60;"> datasource</span>=<span style="color:#f44f4f;">"cfdocexamples"</span><span style="color:#8e44ad;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:#8e44ad;font-weight:bold;"></cfquery></span> |
| 88 |
<span style="color:#8e44ad;font-weight:bold;"></cfif></span> |
| 89 |
<span style="color:#8e44ad;font-weight:bold;"><cfoutput></span> |
| 90 |
<span style="font-weight:bold;"><hr></span>Employee Add Complete |
| 91 |
<span style="color:#8e44ad;font-weight:bold;"></cfoutput></span> |
| 92 |
|
| 93 |
<span style="color:#7a7c7d;"><!--- temperature.cfc ---></span> |
| 94 |
<span style="color:#8e44ad;font-weight:bold;"><cfcomponent></span> |
| 95 |
<span style="color:#8e44ad;font-weight:bold;"><cffunction</span><span style="color:#27ae60;"> name</span>=<span style="color:#f44f4f;">"FtoC"</span><span style="color:#27ae60;"> access</span>=<span style="color:#f44f4f;">"public"</span><span style="color:#27ae60;"> returntype</span>=<span style="color:#f44f4f;">"numeric"</span><span style="color:#8e44ad;font-weight:bold;">></span> |
| 96 |
<span style="color:#8e44ad;font-weight:bold;"><cfargument</span><span style="color:#27ae60;"> name</span>=<span style="color:#f44f4f;">"fahrenheit"</span><span style="color:#27ae60;"> required</span>=<span style="color:#f44f4f;">"yes"</span><span style="color:#27ae60;"> type</span>=<span style="color:#f44f4f;">"numeric"</span><span style="color:#8e44ad;font-weight:bold;"> /></span> |
| 97 |
<span style="color:#8e44ad;font-weight:bold;"><cfset</span><span style="color:#27ae60;"> answer</span>=<span style="color:#8e44ad;font-weight:bold;"> (fahrenheit - 32)*100/180 /></span> |
| 98 |
<span style="color:#8e44ad;font-weight:bold;"><cfreturn answer /></span> |
| 99 |
<span style="color:#8e44ad;font-weight:bold;"></cffunction></span> |
| 100 |
<span style="color:#8e44ad;font-weight:bold;"></cfcomponent></span> |
| 101 |
<span style="color:#7a7c7d;"><!--- test.cfm ---></span> |
| 102 |
<span style="color:#8e44ad;font-weight:bold;"><cfset</span><span style="color:#27ae60;"> fDegrees</span><span style="color:#8e44ad;font-weight:bold;"> </span>=<span style="color:#8e44ad;font-weight:bold;"> 212 /></span> |
| 103 |
<span style="color:#8e44ad;font-weight:bold;"><cfinvoke</span><span style="color:#27ae60;"> component</span>=<span style="color:#f44f4f;">"temperature"</span><span style="color:#27ae60;"> method</span>=<span style="color:#f44f4f;">"FtoC"</span><span style="color:#27ae60;"> returnvariable</span>=<span style="color:#f44f4f;">"result"</span><span style="color:#8e44ad;font-weight:bold;">></span> |
| 104 |
<span style="color:#8e44ad;font-weight:bold;"><cfinvokeargument</span><span style="color:#27ae60;"> name</span>=<span style="color:#f44f4f;">"fahrenheit"</span><span style="color:#27ae60;"> value</span>=<span style="color:#f44f4f;">"#fDegrees#"</span><span style="color:#8e44ad;font-weight:bold;"> /></span> |
| 105 |
<span style="color:#8e44ad;font-weight:bold;"></cfinvoke></span> |
| 106 |
<span style="color:#8e44ad;font-weight:bold;"><cfoutput></span>#fDegrees#<span style="color:#c45b00;">&deg;</span>F = #result#<span style="color:#c45b00;">&deg;</span>C<span style="color:#8e44ad;font-weight:bold;"></cfoutput></span> <span style="font-weight:bold;"><br /></span> |
| 107 |
|
| 108 |
<span style="color:#8e44ad;font-weight:bold;"><cfset</span><span style="color:#27ae60;"> person</span><span style="color:#8e44ad;font-weight:bold;"> </span>=<span style="color:#8e44ad;font-weight:bold;"> CreateObject(</span><span style="color:#f44f4f;">"component"</span><span style="color:#8e44ad;font-weight:bold;">, </span><span style="color:#f44f4f;">"Person"</span><span style="color:#8e44ad;font-weight:bold;">) /></span> |
| 109 |
</pre></body></html> |