Friday, August 8, 2008

Regular Expression

* = zero or many
? = zero or one
+= one or more
"[dl]og" will match dog, or log, but it will not match dlog.
[^dl]og" now we will match any sequence ending in og that isn't preceded with a d or l, such as fog.
a range of characters using the - (dash) character

<cfform id="form1" name="form1" method="post" action="">
<cfinput type="text" name="reg" id="textfield" validate="regular_expression" pattern="([0-3]{3})([a-z]{5})*" /> </label>
<cfinput type="submit" name="button" id="button" value="Submit" />
</cfform>

Input Masking (form validation)

<cfform>
Enter Phone Number: <cfinput type="Text" name="phoneNumber" mask="(+91)(0999)(99999999)"><br>
Enter in Credit Card: <cfinput type="Text" name="CCNumber" value="" mask="9999-9999-9999-9999"><br>
<cfinput type="Submit" name="btn" value="Save">
</cfform>

Tuesday, August 5, 2008

e-Mall Project code

Application.cfm

<cfapplication name="my"
sessionmanagement="yes">

<cfif IsDefined("form.remail")>


<cfquery name="q1" datasource="emall">
select * from reg where email = "#form.remail#" and p = "#form.pass#"
</cfquery>

<cfif #form.remail# eq #q1.email#>
<cfset session.name="#q1.name#">
<cfset session.id="#q1.regID#">
<cfset session.mail="#q1.email#">
</cfif>

</cfif>


To Display Logged User Name

<cfif isDefined("session.name")> (to check variable, session exist or not)
Hi #session.name#
<cfelse>
Hi
</cfif>

To Display Picture or other items for Logged User Only

<cfif isDefined("session.name")>
<div id="apDiv34"><a href="logout.cfm">
<img src="pic/logout_icon copy.jpg" width="50" height="47" /></a></div>
</cfif>





Query Build

<cfquery name="q1" datasource="emall">
select *from dvd
</cfquery>

Add Database Values and Picture to Table

<div id="apDiv21">

<table width="113" border="1">
<tr>
<cfoutput query="q1">
<td width="103">
<a href="viewdvd.cfm?dvdID=#q1.dvdID#">
(Passing Table values to viewdvd.cfm)
<img src="#q1.pic#" width="91" height="119" />
</a>
</td>
</cfoutput>
</tr>
<tr><cfoutput query="q1">
<td>
<div align="center"><span class="style2">#q1.title#</span></div></td>
(Assign database value to table)
</cfoutput>
</tr>
</table>

<div align="center"></div>
</div>




Get Particular Table Row and URL Values

<cfquery name="q1" datasource="emall">
select *from dvd where dvdID=#URL.dvdID#
</cfquery>


To Display Selected Item Details in another page

<div id="apDiv21">

<cfoutput query="q1">
<table border="1">
<tr>
<td width="77"><div align="center"><span class="style2">FILM NAME</span></div></td>
<td width="82"><span class="style2">#q1.title#</span></td>
<td width="221" rowspan ="4">

<img src="#q1.pic#" width="200" height="240" /> </td>
</tr>
<tr>
<td height="102"><span class="style2">STARRING</span></td>
<td><span class="style2">#q1.starring#</span></td>
</tr>
<tr>
<td height="91"><span class="style2">DIRECTOR</span></td>
<td><span class="style2">#q1.director#</span></td>
</tr>
<tr>
<td><div align="center"><span class="style2">PRICE</span></div></td>
<td><span class="style2">$#q1.price#</span></td>
</tr>

</table>
</cfoutput>
</div>


To Display Add to Cart Button if Logged User exist and Product ID , User ID passes to another page for Insertion

<cfif isDefined("session.name")>
<cfform name="form1" id="form1" method="post" action="addcart.cfm?pid=#q1.dvdID#&pname=#q1.title#">
<cfinput type="submit" name="Submit" value="Add to Cart">
</cfform>
</cfif>

To User Purchased Items and User ID in Database

<cfif (isDefined ("URL.pid")AND isDefined("URL.pname"))>
(Here to checking URL.variable exist or not)

<cfquery name="q2" datasource="emall">
insert into shop (userid, username, productid, productname) values (#session.id#,'#session.name#','#URL.pid#','#URL.pname#')
</cfquery>
</cfif>

CFCALENDER

<cfform format="html" width="400" height="300">
<center>
<cfcalendar
name="calDate"
selectedDate="#dateFormat(now(), 'yyyy-mm-dd')#"
dayNames="S,M,T,W,T,F,S"
monthNames="Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"/>

<cfinput name="submit" value="Submit" type="submit" style="width:80;">
</center>
</cfform>

<cfif isDefined("form.submit")>
The date you selected was <cfoutput>#form.calDate#</cfoutput>.
</cfif>

HISTORY BACK USING JAVA SCRIPT

<a href="javascript:history.back();">Back</a>

CFMENU AND CFMENUITEM

<cfmenu type="horizontal"
selecteditemcolor="##CC00CC" //selected item color
selectedfontcolor="##CCFF33" //selected font color
menustyle="background-color:##FFF333" //Menu bgcolor
childstyle="background-color:##FFF333"> //menu tab bgcolor

<cfmenuitem display="Software" childstyle="background-color:##CCFF44" >
<cfmenuitem display="J2ee" />
<cfmenuitem display="Coldfusion"/>
<cfmenuitem display="Dot Net"/>

</cfmenuitem>
</cfmenu>



<cfmenu type="vertical"
selecteditemcolor="##CC00CC"
selectedfontcolor="##CCFF33"
menustyle="background-color:##FFF333"
width="120"
childstyle="background-color:##FFF333">

<cfmenuitem display="Software" childstyle="background-color:##CCFF44" >
<cfmenuitem display="J2ee" />
<cfmenuitem display="Coldfusion"/>
<cfmenuitem display="Dot Net"/>

</cfmenuitem>
</cfmenu>

CFWINDOW

To Create Window within Browser

<cfwindow bodystyle="background-color:##CC6633"
draggable="true"
height="450"
width="400"
headerstyle="background-color:##CC0000; color:##CCFF33"
x="20"
y="45"
initshow="true"
modal="false"
title="Ganesh">
</cfwindow>

CFIMAGE

To Set Path

<cfset pic=ExpandPath("../temp/sm3.jpg")>
<cfimage source="#pic#" action="writetobrowser">


Display image with border

<cfimage source="#pic#" action="border" name="new" color="##0000FF">
<cfimage source="#new#" action="writetobrowser">


Display image with resizable

<cfimage source="#pic#" action="resize" width="70" height="90" name="new">
<cfimage source="#new#" action="writetobrowser">

Display image resizable and rotation

<cfimage source="#pic#" action="rotate" angle="45" name="new1">
<cfimage source="#new1#" action="resize" height="90" width="70" name="new">
<cfimage source="#new#" action="writetobrowser">

CFLAYOUT

<cflayout type="tab" style="background-color:##FF9900">
<cflayoutarea title="one" style="border:thin">
one
</cflayoutarea>
<cflayoutarea title="two" style="border: thin">
two
</cflayoutarea>
</cflayout>

Upload

<cfif isDefined("form.file1")>
<cffile action="upload"
fileField="file1"
destination="D:\ColdFusion8\wwwroot">
</cfif>

cfdump

(It's just as easy to use cfdump on a complex object as it is on a simple variable)

<cfquery name="q1" datasource="emall">
select *from dvd
</cfquery>

<cfdump var="#q1#">

Date Difference

<cfoutput>
#DateDiff("d", Now(), CreateDate(1983,5,29))# days til the 9/11 2 year anniversary.
</cfoutput>

Redirection Permanently

<cfheader statuscode="301" statustext="Moved Permanently">
<cfheader name="Location" value="home.cfm">

Redirection

<cflocation url="/new_location.cfm">

List

<cfset l="a,b,x,c,d,e,f,g,gh,i">
listAppend(l,11)

<cfoutput>
#listLen(l)#
</cfoutput>

listAppend(coldfusion_list, "ColdFusion Functions")
listPrepend(coldfusion_list, "ColdFusion Functions")
listInsertAt(coldfusion_list, "2", "ColdFusion Functions")
listContains(coldfusion_list, "ColdFusion")
listContains(coldfusion_list, "ColdFusion")
listContainsNoCase(coldfusion_list, "ColdFusion")
ListToArray(coldfusion_list)
ArrayToList(array_name)

Array

<cfset a=ArrayNew(1)> (array Creating)
<cfloop from=0 to=10 index="i">

<cfset ArrayAppend(a,i)> (array element inserting)

</cfloop>

<cfloop from=5 to=10 index="i">
<cfoutput> #a[i]#</cfoutput>
</cfloop>

ArrayAppend (add element in end)
ArrayPrepend (add element at begin)
ArrayInsertAt (array element at nth position)

Structure Implementation 2: Number

<cfset data=StructNew()>
<cfset a=StructInsert(data,1,"Apple")>
<cfset b=StructInsert(data,2,"Bed")>
<cfset c=StructInsert(data,3,"Cats")>
<cfloop collection="#data#" item=z>
<cfoutput>
#z#:#StructFind(data,z)#<br />
</cfoutput>
</cfloop>

Structure Implementation 1: String

<cfset data=StructNew()>
<cfset a=StructInsert(data,"A","Apple")>
<cfset b=StructInsert(data,"B","Bed")>
<cfset c=StructInsert(data,"C","Cat")>
<cfloop collection="#data#" item="z">
<cfoutput>
#z#:#StructFind(data,z)#<br />
</cfoutput>
</cfloop>

List loop

<cfloop list="a+b+c+d+e+f" index="lists"delimiters="+">
<cfoutput>#lists#</cfoutput>
</cfloop>

Loop in Query

<cfquery name="q1" datasource="emall">
select userid from shop
</cfquery>

<cfloop query="q1">
<cfoutput>#userid#</cfoutput>
</cfloop>

Loop

<cfloop from=1 to=10 index="i">
<cfoutput>
Hi #I#
</cfoutput>
</cfloop>

If condition

<cfif value1 == value2 >
eq
gt
lt
gte
lte
</cfif>

To define scope for variable for avoid confusion

<cfset a.a=10>
<cfset b.a=100>
<cfoutput>
#a.a# //10
#b.a# //100

</cfoutput>

To assign default value

<cfset a=10> (if it is not assign the default value can be taken)
<cfparam name="a" default="103">
<cfoutput> #a# </cfoutput>

To Include anther file

<cfinclude template="home.cfm">

Print

<cfoutput>
hi
</cfoutput>