Basic Grammar in ColdFusion


I would like to share basic grammar in ColdFusion.

🗻 How ColdFusion Work

ColdFusion code is compiled into Java byte-code. ColdFusion is made up of two parts:

  • ColdFusion Application Server
  • ColdFusion Markup Language (CFML)

🍄 What is ColdFusion Markup Language

  • The ColdFusion Markup Language (CFML) looks similar to HTML in which is tag-based.(e.g, <cfloop>)
  • CFML is also includes fully functionally built-in scripting language similar to JavaScript

😼 Cheat Sheet for Basic Grammer

Variables

<!--- Original Variable --->
<cfset VARIABLES.greeting="Hello">

<!--- Passing Variables on the URL (HelloHi.cfm?greet=Hello) --->
<cfoutput>#URL.greet#</cfoutput>

Comment

<!-- This is an HTML comment -->
<!--- This is a ColdFusion comment --->

Builtin Functions

ColdFusion has a lot of functions for performing all sort of tasks, etc.

#DateFormat(Now(),"dddd, mmmm d, yyyy")#

If you want to know more detail, please see ColdFusion functions by category

Arithmetic and String Operation

ColdFusion has some Arithmetic and String Operations:

<!--- Atrithmetic Operation --->
<cfset c = a + b>

<!--- String Operation --->
<cfset c = a + b>

If you want to know more detail, please see Expressions-Developing guide

Conditional Processing

<!--- If-Else if-Else Blocks --->
<cfif><cfelseif><cfelse></cfif>

<!--- Switch Blocks --->
<cfset Quantity = 1>
<cfswitch expression="#Quantity#">
<cfcase value="1">Quantity is 1</cfcase>
<cfdefaultcase>Quantity is not 1</cfdefaultcase>
</cfswitch>

List

<cfset numlist="1,2,3,4,5">
<cfloop index="num" list="#numlist#">
<cfoutput>#num#</cfoutput>
</cfloop>

If you want to know more detail about List functions, please see List functions

Array

<!--- One-dimensional Arrays -->
<cfset beatles = ArrayNew(1)>
<cfset ArrayAppend(beatles,"John")>
<cfset ArrayAppend(beatles,"Paul")>

<cfloop from="1" to="#ArrayLen(beatles)#" index="i">
<div><cfoutput>#beatles[i]#</cfoutput></div>
</cfloop>

<!--- Two-dimensional Arrays -->
<cfset rockbands=ArrayNew(2)>
<cfset rockbands[1][1]="Beatles">
<cfset rockbands[1][2]="Love Me Do">

<cfloop from="1" to="#ArrayLen(rockbands)#" index="i">
<cfloop from="1" to="#ArrayLen(rockbands[i])#" index="j">
<div>#rockbands[i][j]#</div>
</cfloop>
</cfloop>

If you want to know more detail about Array functions, please see Array functions

Form

HTML with form:

<!--- Use HTML form --->
<form method="post" action="form-receive.cfm">
<input name="yourname" type="text" size="30">
<input type="submit" value="submit">
</form>

<!--- Use cfform tag --->
<cfform name="RunningForm" method="post" action="AddEntry-cfform.cfm" format="html">
<cfinput type="text" name="date" size="20">
<cfinput type="submit" name="Add Entry" value="Add Entry">
</cfform>

Receive form data:

<cfoutput>
<b>Your name:</b> #FORM.yourname#
</cfoutput>

cfform tag supports validation:

Suffix Description
numeric Accept only Numeric input
require Check that the value exists
email Valid email address

😸 Next

TOBED

https://www.webucator.com/tutorial/learn-coldfusion/database-access-authentication/a-database-less-login-form-reading.cfm#tutorial

🎃 Special Thanks

🖥 Recommended VPS Service

VULTR provides high performance cloud compute environment for you. Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour). In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!