Thursday, September 25, 2008

sitemap

sitemap


Dynamically populate the second drop down list based on the First Dropdown list

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<!--- store the selected Main_Group variable variable after the first select boxes submits itself --->
<cfif isDefined('form.select_Main_Group')>
<cfset page.select_Main_Group = form.select_Main_Group>
</cfif>

<cfoutput>
<form name="DropDown" method="post">
<!--- query DB for the first drop down list --->
<cfquery name="get_Main_Group" datasource="cflearn">
SELECT id,Lastname
FROM employee1
</cfquery>

<!--- first drop down list --->
<!--- NOTICE the onChange javascript event in the select tag, this is what submits the form after the first selection --->
<select name="select_Main_Group" required="yes" onchange="this.form.submit()">
<option>Select Main Group</option>
<!--- dynamically populate the first drop down list based on the get_Main_Group query --->
<!--- NOTICE the CFIF within the option tag, this says, if the first selection has been made, display the chosen option when the page reloads --->
<cfloop query="get_Main_Group">
<option value="#id#" <cfif isDefined('form.select_Main_Group')><cfif form.select_Main_Group eq "#id#">selected</cfif></cfif>>#Lastname#</option>
</cfloop>
</select>
<p>
<!--- if the first selection has been made, display the second drop down list with the appropriate results --->
<cfif isDefined('page.select_Main_Group')>
<!--- query DB for second drop down list, based on the selected item from the first list --->
<cfquery name="get_Sub_Group" datasource="cflearn">
SELECT id, Firstname
FROM employee
WHERE id = #page.select_Main_Group#
</cfquery>

<!--- second drop down list --->
<!--- <select name="select_Sub_Group" required="yes">
<option>Select Subgroup</option>--->
<!--- dynamically populate the second drop down list based on the get_Sub_Group query --->
<!--- <cfloop query="get_Sub_Group">
<option value="#id1#">#Firstname#</option>
</cfloop>
</select>--->
<cfloop query="get_Sub_Group">
<table>
<tr>
<td>
#firstname#
</td>
</tr>
</table>
</cfloop>
</cfif>
</form>
</cfoutput>
</body>
</html>

Drop down onfocus and Radio button validation

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="JavaScript" type="text/javascript">
function ValidateForm(form)
{
if(form.name.value=='')
{
alert('You did not enter your name')
form.name.focus();
return false;
}
if(form.email.value=='')
{
alert('You did not enter your email address')
form.email.focus();
return false;
}

dropDownMenu = document.getElementsByName('hear')
if(dropDownMenu[0].selectedIndex==0)
{
alert('You must make a choice');

form.hear.focus();
return false;
}
if(form.sub.value=='')
{
alert('You must make a choice');

form.hear.focus();
return false;
}
//RADIO BUTTON VALIDATION
var checked = false;
var buttons = form.elements.sub;
for (var i=0; i<buttons.length; i++)
{
if (buttons[i].checked) {
checked = true;
break;
}
}
if(!checked)
alert("you have to choose a one radio button");
return checked ;

return true;
}//-- end ValidateForm()
-->
</script>
</head>
<body>
<!-- begin form -->
<form action="#" method="POST" name="nerdForm" onsubmit="return ValidateForm(this)">
<table cellpadding="2" cellspacing="2" class="form" bgcolor="#FFFF33">
<tr>
<td colspan="2" class="title">Items in <span class="announce">red</span> are required items</td>
</tr>
<tr>
<td class="announce">Name</td>
<td><input type="text" size="22" maxlength="22" class="input" name="name"></td>
</tr>
<tr>
<td class="announce">Email Address</td>
<td><input type="text" size="22" maxlength="35" class="input" name="email"></td>
</tr>
<tr>
<td>Phone</td>
</td>
<td><input type="text" size="22" maxlength="22" class="input" name="phone"></td>
</tr>
<tr>
<td class="announce">How did you hear about us?</td>
<td><select name="hear" class="input">
<option value="">Please choose...</option>
<option value="friend">Friend</option>
<option value="interent">Internet</option>
<option value="ad">Advertisement</option>
</select>
</td>
</tr>
<tr>
<td class="announce">Would you like to Subscribe?</td>
<td>Yes
<input type="radio" value="yes" name="sub">
No
<input type="radio" value="no" name="sub"></td>
</tr>
<tr>
<td colspan="2" class="center"><input type="submit" value="Submit" class="button ">
  
<input type="reset" value="Clear" class="button">
</td>
</tr>
</table>
</form>
<!-- end form -->
</body>
</html>

Friday, September 19, 2008

Random password generator in CF

<cfset ststring=structNew()>
<cfloop index="i" from="1" to="6" step="1">

<!--- let ?a? be random number between 48 and 122. Thus this will include everything from 0 to 9, Capital A to Z and small case a to z. --->

<cfset a = randrange(48,122)>

<!--- This is where the stucture is populated, Conceptually, ststring is a new structure specified above....ststring1 is key 1, ststring2 is key 2, ststring3 is key 3, and so on --->

<!--- since all characters between 57 and 65 and those between 90 and 97 are charachters like "[,],+,=,..,$,#" and so on, we don't need them. Unless ofcourse yours is a password with special characters. That explains the condition below. If our randrange givers a number like 92, we don't need it and I chose to subtitue it with an "E"...you can use your own substitution. --->

<cfif (#a# gt 57 and #a# lt 65) or (#a# gt 90 and #a# lt 97)>
<cfset ststring["#i#"]="E">
<cfelse>
<cfset ststring["#i#"]=#chr(a)#>
</cfif>

</cfloop>


<!--- Now that our password is made up of 6 stings, it is just a question of putting that together, thus ... --->

<cfset stpassword ="#ststring[1]##ststring[2]##ststring[3]##ststring[4]##ststring[5]##ststring[6]#">


<!--- In principle, take each variable in a string of six, and assign a character to it which falls between 48 to 57 or 65 to 90 or 97 to 122 --->

Randomly Generated Password : <b><cfoutput>#stpassword#</cfoutput></b>

<!--- let me know if you think of any improvements on this one --->

Thursday, September 18, 2008

password validation on capslock on

<html>
<head>
<script language="Javascript">

function capLock(e) {
kc = e.keyCode?e.keyCode:e.which;
sk = e.shiftKey?e.shiftKey:((kc == 16)?true:false);

if(((kc >= 65 && kc <= 90) && !sk)||((kc >= 97 && kc <= 122) && sk))
{
document.getElementById('divMayus').style.visibility = 'visible';
}
else
{
document.getElementById('divMayus').style.visibility = 'hidden';
}
}
</script>
</head>
<body>
<table>
<tr>
<td>
<input type="password" name="txtPassword" onkeypress="capLock(event)" />
</td>
<td>
<div id="divMayus" style="visibility:hidden">Caps Lock is on.</div>
</td>
</tr>
</table>
</body>
</html>

RSSfeed IN Coldfusion

Creating RSSfeeds IN Coldfusion:-
When you create a feed, you specify the feed contents in a name structure or in the combination of a query object and a properties structure. The cffeed tag generates the feed XML and saves in to the variable specified by the xmlVar attribute, the file specified by the outputFile attribute, or both.
To create an RSS 2.0 feed you must specify the following metadata fields in a name structure or in a properties structure. All other RSS2.0 metadata fields, and all item fields, are optional.
title
link
description
version (must be "rss_2.0")
The cffeed tag does not enforce any rules on the Atom feed structure that it creates. You are responsible for ensuring that the feed is valid.
In most cases, a database table uses column names that differ from the column names you must use to create the feed. Therefore, you must use the columnmap attribute to map the input query column names to the required column names. The attribute is a structure whose keys are the column names required by the cffeed tag and whose values are the corresponding input query columns. The following example creates a feed using the cfartgallery data source's orders table. It maps the orders table ORDERDATE column to the query publisheddate column, the ADDRESS column to the content column, and so on. The sample code then displays the generated query XML to show the results.
<!--- Get the feed data as a query from the orders table. --->
<cfquery name="getOrders" datasource="cfartgallery">
SELECT * FROM orders
</cfquery>

<!--- Map the orders column names to the feed query column names. --->
<cfset columnMapStruct = StructNew()>
<cfset columnMapStruct.publisheddate = "ORDERDATE">
<cfset columnMapStruct.content = "ADDRESS">
<cfset columnMapStruct.title = "CUSTOMERFIRSTNAME">
<cfset columnMapStruct.rsslink = "ORDERID">

<!--- Set the feed metadata. --->
<cfset meta.title = "Art Orders">
<cfset meta.link = "http://feedlink">
<cfset meta.description = "Orders at the art gallery">
<cfset meta.version = "rss_2.0">

<!--- Create the feed. --->
<cffeed action="create"
query="#getOrders#"
properties="#meta#"
columnMap="#columnMapStruct#"
xmlvar="rssXML">

<cfdump var="#XMLParse(rssXML)#">

Reading feeds
The cffeed tag does not validate the feeds that it reads. It can read invalid or loosely formatted feeds, but ignores some or all of the invalid content. For example, if you put more than one rights element in the Atom feed (which invalidates the feed), the cffeed tag ignores the elements after the first one, and doesn't generate an error.
Dates and times in feeds that are being read must be in W3C or RFC 822 format. ColdFusion can also read iTunes extension dates in the format normally used by the iTunes music store.
Example
The following example creates an RSS feed. You must enter fields for the feed title, link, and description elements. You must also enter title, link, and description fields for one item. A second item is optional. The application saves the feed in a createRSSOutput.xml file in the feedTest subdirectory of the directory that contains the CFML page.
<!--- Generate the feed when the user submits a filled in form. --->
<cfif isDefined("Form.Submit")>
<cfscript>

// Create the feed data structure and add the metadata.
myStruct = StructNew();
mystruct.link = form.link;
myStruct.title = form.title;
mystruct.description = form.description;
mystruct.pubDate = Now();
mystruct.version = "rss_2.0";

/* Add the feed items. A more sophisticated application would use dynamic variables
and support varying numbers of items. */
myStruct.item = ArrayNew(1);
myStruct.item[1] = StructNew();
myStruct.item[1].description = StructNew();
myStruct.item[1].description.value = form.item1text;
myStruct.item[1].link = form.item1link;
myStruct.item[1].pubDate = Now();
myStruct.item[1].title = form.item1title;
myStruct.item[2] = StructNew();
myStruct.item[2].description = StructNew();
myStruct.item[2].description.value = form.item2text;
myStruct.item[2].link = form.item2link;
myStruct.item[2].pubDate = Now();
myStruct.item[2].title = form.item2title;

</cfscript>

<!--- Generate the feed and save it to a file and variable. --->
<cffeed action = "create"
name = "#myStruct#"
outputFile = "feedTest/createRSSOutput.xml"
overwrite = "yes"
xmlVar = "myXML">

</cfif>

<!--- The user input form. --->
<cfform format="xml" preservedata="yes" style="width:500" height="700">
<cfformitem type = "text"> Enter The Feed Metadata</cfformitem>
<cfinput type = "text" label = "title" name = "title"
style = "width:435" required = "yes"> <br />
<cfinput type = "text" label = "link" name = "link"
style = "width:435" required = "yes" validate = "url"> <br />
<cftextarea name = "description"
style = "width:435; height:70" required = "yes" />

<cfformitem type = "text"> Enter Item 1</cfformitem>
<cfinput type="text" label="title" name="item1title"
style="width:435" required="yes"> <br />
<cfinput type="text" label="link" name="item1link"
style="width:435" required="yes" validate="url"> <br />
<cftextarea name = "item1text"
style = "width:435; height:70" required = "yes" /> <br />

<cfformitem type = "text"> Enter Item 2</cfformitem>
<cfinput type = "text" label = "title" name = "item2title" style = "width:435"> <br />
<cfinput type = "text" label = "link" name = "item2link" style = "width:435"
validate = "url"> <br />
<cftextarea name = "item2text" style = "width:435; height:70" /> <br />

<cfinput type = "Submit" name = "submit" value = "Submit" >
</cfform>

The following application is a simple feed reader that handles RSS and Atom feeds. It displays the feed title; for each item or entry, it shows the title as a link, and shows the published date and the item or entry contents. To use this example to read the feed created by the first application, enter the URL for the file the application created, for example, http://localhost:8500/cffeed/feedTest/createRSSOutput.xml.
<!--- Process the feed data if the user submitted the form --->
<cfif isDefined("Form.Submit")>
<cffeed source = "#theURL#"
properties = "myProps"
query = "myQuery">

<!--- Display the feed output.
Use conditional logic for to handle different feed formats. --->
<cfoutput>
<h2>#myProps.title#</h2>
</cfoutput>
<cfoutput query = "myQuery">
<cfif myProps.version IS "atom_1.0">
<h3><a href = "#linkhref#">#title#</a></h3>
<p><b>Published:</b> #DateFormat(publisheddate)#</p>
<cfelse>
<h3><a href = "#rsslink#">#title#</a></h3>
<p><b>Published:</b> #publisheddate#</p>
</cfif>
<p>#content#</p>
</cfoutput>
</cfif>

<!--- The form for specifying the feed URL or file --->
<cfform name = "SetFeed" preserveData = "yes">
Enter Feed URL:
<cfinput type = "text" size = "60" name = "theURL"><br><br>
<cfinput type = "Submit" name = "submit" value = "Submit">
</cfform>

Sunday, September 14, 2008

processing page, please wait", made easy! in cf

<!--- First thing we need to do is layout a form that will contain our 'processing' page --->
<body bgcolor="#514a4d" topmargin="60" leftmargin="10">
<form name="process">
<table width="650" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#FFFFFF" vspace="0">
<TR>
<TD colspan="2" align="center">
<div id="Processing" style="visibility:visible;">
<h2>Report Processing, please wait...</h2>
</div>
</TD>
</TR>
<TR>
<TD align="center">
<input name="Status"
value="Processing Status:"
width="25"
maxlength="25"
style="border:0px; background-color:##FFFFFF;">
</TD>
<TD>
<input name="Percent" width="8" maxlength="8" style="border:0px; background-color:##FFFFFF " value="">
</TD>
</TR>
<TR>
<TD colspan="2">
<div id="Complete" style="visibility:hidden; position:relative; ">
<center>
Your report is complete!.
</center>
</div>
</TD>
</TR>
</table>
</form>
<cfflush>

<!--- Create a 'CurrentPercent' variable --->
<cfparam name="CurrentPercent" type="string" default="">

<!--- Here we would normally do a query, but I am going loop through a list for an example --->
<cfloop from="1" to="10" step="1" index="i">

<cfoutput>
<cfset CurrentPercent = '#i * 10#'>
<script>
document.process.Percent.value = #CurrentPercent# + '%';
</script>
<cfflush>
</cfoutput>

<!--- Include your processing here, or use a cfinclude like I did --->
<!--- In this case, I will put a 1 second pause here --->
<CFSET StartWait = Now()>
<CFLOOP condition="DateDiff('s', Variables.StartWait, now()) lt 1">
</CFLOOP>

<!--- Check if we are at 100 percent --->
<cfif CurrentPercent eq 100>
<script>
document.process.Percent.value = 'Complete';
</script>
</cfif>

</cfloop>

<!--- Make the 'processing page' text disappear --->
<script>
document.getElementById('Processing').style.visibility = 'hidden';
</script>

What is a custom tag in coldfusion

What is a custom tag and why do i need it?
This is a question I get a lot when I bring up custom tags. A custom tag is a piece of code that you create and you call it from within your ColdFusion applications. Think of it as a "SNIPPLET" that you can implement at any time, anywhere in your site. What can you do with a custom tag? Well, just about anything!
In this tutorial I will demonstrate how you can use a custom tag to add a list of states (in a drop down select box) in a form.
Let's see how you call a custom tag. The easiest (and probably most used) method is: <cf_states>.
What does that mean?
Ok, you are simply telling ColdFusion to look in the same folder (as the file you are accessing to call the custom tag) or in the custom tags folder (Usually C:\CFusion\CustomTags\) for a file called: states.cfm. If it finds that file, you are saying to the server, execute it, process it and send me the results of it. So it's like an include, but with the difference that you can do other neat things! I'll explain more below.

You can pass values to the custom tag, as follows:
<cf_states DefaultState="TX"
FieldName="States">
This basically says that when executing the custom tag "states.cfm" the default state I want selected is "TX - Texas". Of course you'll have to write the code that will select the stat, but it's basically allowing you to tell the code in the "states.cfm" file that that is the default state. Let's create the actual states.cfm file so you can see how it works. Notice also that I'm passing a value called "FieldName" this will become the name of the form field that will be generated. That ay when you process the page in the end you'll know what name to reference.
(Note: Since you are specifying a variable for the custom tag called "DefaultState", within the custom tag, this variable is referenced as follows: "Attributes.DefaultState". All variables you pass when calling the tag (i.e. one="" two="") will always be referenced within the custom tag as "Attributes.[name of variable]".)
<!--- States.cfm custom tag --->
<!--- Make sure that user specified a name for the form field --->
<cfif NOT IsDefined("Attributes.FieldName")>
<!--- No Name Was Specified, stop custom tag and ask that user specify field --->
<font color="red" size="4" face="Verdana">You did not specify a valid name for the select field!</font>
<cfabort>
</cfif>
<!--- define a variable called "Attributes.DefaultState" to be Arizona --->
<cfif NOT IsDefined("Attributes.DefaultState")>
<!--- No Default State Was Define, Set Default To Be Arizona --->
<cfset Attributes.DefaultState = "AZ">
</cfif>

<!--- Now Create the Select Box With The States --->
<cfoutput>
<select name="#Attributes.FieldName#">
<option value="AZ"<cfif Attributes.DefaultState eq "AZ"> SELECTED</CFIF>>AZ - Arizona</option>
<option value="CA"<cfif Attributes.DefaultState eq "CA"> SELECTED</CFIF>>CA - California</option>
<option value="MS"<cfif Attributes.DefaultState eq "MS"> SELECTED</CFIF>>MS - Mississippi</option>
<option value="NJ"<cfif Attributes.DefaultState eq "NJ"> SELECTED</CFIF>>NJ - New Jersey</option>
<option value="NY"<cfif Attributes.DefaultState eq "NY"> SELECTED</CFIF>>NY - New York</option>
<option value="TX"<cfif Attributes.DefaultState eq "TX"> SELECTED</CFIF>>TX - Texas</option>
</select>
</cfoutput>
OK, so what was the purpose of this custom tag? Well imagine that you are building 30 web sites for 30 different customers that all ask for users information. So now with this custom tag you can simply type in:
<cf_states DefaultState="TX"
FieldName="States">
So for customer one you created an automatic states drop down in the form on the fly.
Now say your second customer likes that the database values be written as tblflStates and the default state for this customer has to be New York. So in the "FieldName" you can no longer use "states". If you hadn't used a custom tag you'd have to recreate the file, use unnecessary space and waste time with something you could of already have had done. So for this customer so simple modify as follows:
<cf_states DefaultState="NY"
FieldName="TblflStates">
Are you starting to see the value of Custom tags? Well in short they're a way for you reuse your code easily and fast!
You can also do other neat things with them, but that's a whole other tutorial! :)
Congratulations, you now know how custom tags work!

Querying a Query in coldfusion

Querying a Query
<!--- This will show you how to query a query --->
<!--- What this page does is query my db for all tickets entered between
2 dates and then it takes those tickets and finds the ones that have the specific
value of "closed" and then takes the time between those dates for each ticket and calculates
the avg time it took for someone to close the ticket --->

<!--- This is where you select all records from date1 thru date2 --->


<cfquery name="received" datasource="database">
select RecvdDate, CallStatus
from database
where recvddate between <cfqueryparam value="2003-05-01">
and <cfqueryparam value="2004-05-01">
</cfquery>

<!--- This is where you query the above query and take the data that is returned from it and
Query it again with another instance --->
<CFQUERY NAME="closed" dbtype="query">
select RecvdDate, CallStatus
from received
where callstatus = 'Closed'
</CFQUERY>
<!--- These two queries basically find the number of tickets opened in a 1yr period
And then finds how many of the tickets were closed during that time --->

<!--- This is where you find the average time it took to close a ticket --->
<cfset diffcount = 0>
<cfoutput query="closed">
<!--- diffcount is eq to 0 + the the # of 'days' between the two dates --->
<cfset diffcount = diffcount + dateDiff('d', recvddate, closeddate)>
</cfoutput>
<cfset dateavg = diffcount/closed.recordcount>

<!--- This is the output --->

<table>
<tr>
<th>Between 05/01/2003-05/01/2004</th>
</tr>
<tr>
<td>No. of Tickets Opened:</td>
<!--- No. of records returned from 1st query --->
<td><cfoutput>#received.recordcount#</cfoutput></td>
</tr>
<tr>
<td>No. of Tickets Closed:</td>
<!--- No. of records returned from 2nd query --->
<td><cfoutput>#closed.recordcount#</cfoutput></td>
</tr>
<tr>
<!--- This is where you find the average - use the round statement to make your data
look cleaner. It returns #.## instead of #.########## --->
<td>Avg. Turn-Around:</td>
<td><cfoutput>#Evaluate(round(dateavg*100)/100)#</cfoutput> Days</td>
</tr>
</table>

RSS Feed to CF Query

Simple RSS to CF Query
Overview
This quick and easy function converts an RSS feed XML document into a coldfusion query for you to easily loop through and use on your website.
Files Included in this ZIP (download zip file)
rssFeed.xml An example RSS feed for this tutorial
xml.cfc CFC containing the function required
queryDump.html Dump of the resultant CF Query
Usage
1. Use CFHTTP to obtain the XML packet.
2. Then make sure it’s a valid XML packet
3. Simply invoke the CFC method and pass the function the parameters required as listed below:
• xmlPacket: A valid XML packet returned from the RSS Feed
• parentTree: The parent tree item in the RSS XML Feed
• childElement The child item containing the appropriate data required
The data will be returned to you in a CF query with the column names named exactly the same as the XML tree items.
Example
//Get your RSS Data as you normally would<b>

<cfhttp url="http://www.spunkycash.com/rss-thumb/125x150/0/856346"
method="GET"
timeout="20">
// Make sure it’s a valid XML Packet
<cfscript>
xmlContent = Trim(cfhttp.filecontent);
xmlContent = XMLParse(xmlContent);
</cfscript>
// Method call to convert XML into CF query
<cfinvoke component="xml.cfc"
method="xmlToQuery"
xmlPacket="#xmlContent#"
parentTree="rss.channel"
childElement="item"
returnVariable="qXML">
<cfdump var="#qXML#"> </b>

In Action
If you use the exact code above, it will fetch the RSS feed as seen in the included file (rssFeed.xml). It will then return the query as seen in the included file (queryDump.html).

Check for an IP Address in coldfusion



<CFIF #left(cgi.remote_addr,7)# is "192.168">
<!--- Your code goes here --->
<cfelseif #left(cgi.remote_addr,7)# is not "192.168">
<CFlocation url = "http://www.yahoo.com">
</cfif>



The CFIF tag checks the left "7" digits of the incoming IP which is the cgi.remote_addr variable. If it meets the condition, the code is executed, if not and it meets the cfelseif then the page is redirected to Yahoo.com.

Pretty simple security to make sure requests only come from certain IPs.

password recovery in coldfusion

Users and Forgotten Passwords

You know the situation. You require your visitors to create a username and password in order to access your Web site (or at least certain sections). And of course, 90% of those users will forget their password within the first week.

It?s an inconvenience for them if they have to wait for you to send them their password. The Web is about instant gratification, and there?s just too much competition out there to risk a situation like that.

This tutorial will deal with two possible ways that you can resolve this situation.

E-mailing a Password

This method will allow a user to enter their user name and/or e-mail address, and an e-mail will automatically be sent to them with their password.

In order for this to work, let?s assume a database setup as follows:
tbl_user
column name datatype

userID autonumber/identity
username char
password char
email char
This is merely a suggestion. userID is a primary key; a unique autonumber. However, it?s not really necessary. In theory, usernames should be unique, as well as e-mail addresses. Either of those could just as well serve as primary key, negating the need for the userID column.

It is important to make sure that email addresses are unique. When new users sign up, check the database to make sure the email the new user is signing up with is not already in the database. If it is, prompt the user to enter a different e-mail address (or, if they have an account but forgot their password, offer to send them their password via the method outlined below).

In our database, we might have records such as:

userID Username password email
1 CJ 123abc charlie@griefer.com
2 BillyBob 987xxx bb@aol.com
What happens if CJ forgets his password? Well, we already know his e-mail address (charlie@griefer.com)?so we can easily send him his password.

This process requires two pages?one to allow the user to enter their e-mail address, and another to validate the user, and send the user their password.

password_request.cfm


<html>
<head>
<title>Password Request</title>
</head>

<body>

<form action=?password_send.cfm? method=?post?>
Please enter your e-mail address below:
<input type=?text? name=?email? />
<br />
<input type=?submit? value=?proceed? />
</form>

</body>
</html>


password_send.cfm


<!--- see if this email address exists in the database --->
<cfquery name=?checkEmail? datasource=?myDSN?>
SELECT username, password
FROM tbl_user
WHERE email = <cfqueryparam value=?#trim(form.email)#? cfsqltype=?cf_sql_char?>
</cfquery>

<html>
<head>
<title>Password Request</title>
</head>

<body>

<!--- was a record returned from the query? --->
<cfif checkEmail.recordCount>

<cfmail to=?#form.email#?
from=?webmaster@yoursite.com?
subject=?your password?>
Hello #checkEmail.username#.

You recently requested your password from [NAME OF YOUR WEB SITE HERE].

Your password is: #checkEmail.password#.

Please write this down for future reference.

Thank You,
Webmaster
</cfmail>

Thank you, #checkEmail.username#. Your password has been sent and should
arrive shortly.

<!--- no record found, display message to the user --->
<cfelse>

We?re sorry. We were unable to locate that email address in our database. Please <a href=?password_request.cfm?>try to enter your email address again</a>.

</cfif>



That?s it! Your visitors can now get results immediately.


Using a Secret Question

There?s another method that some sites employ that don?t? even require your visitors to have to wait for an email.

This would entail asking the visitor a ?secret question?. Something only he or she would know, in order to prove their identity.

This will require two additional columns in the table that we used above:
tbl_user
column name datatype

userID autonumber/identity
username char
password char
email char
secretQuestion char
secretAnswer char
As you can see, we?re storing a secret question (and answer) for each user. This information would be gathered during their initial sign up process. You can possibly provide them with a list of secret questions, of which they get to pick one?

for example:
• mother?s maiden name
• favorite sport?s team
• favorite pet name
• street you grew up on
Store both the question, and the answer the user enters into the database.

This method will require 3 templates:
1. a template where the visitor can enter their user name
2. a template that retrieves/displays the secret question, and allows the user to input the answer
3. a template that checks the given answer against the database, and displays the results to the user.
password_request.cfm
<!--- this is the template that will allow the user to enter his/her username --->

<html>
<head>
<title>Request Password</title>
</head>

<body>

<form action=?display_question.cfm? method=?post?>
Please enter your user name below, and click ?proceed?.
<br /><br />
<input type=?text? name=?username? />
<input type=?submit? value=?proceed? />
</form>

</body>
</html>



display_question.cfm
<!---
this template checks the username entered on the previous page. if no username was found, the form is displayed again, and the user is asked to re-enter their username.

if a username is found, we output the secret question, with a form to collect the answer. it?s important to note that we are passing the username to the next template in a hidden form field!
--->


<cfquery name=?getQuestion? datasource=?myDSN?>
SELECT secretQuestion
FROM tbl_user
WHERE username = <cfqueryparam value=?#trim(form.username)#? cfsqltype=?cf_sql_char?>
</cfquery>

<html>

<head>
<title>Request Password </title>
</head>

<body>

<cfif getQuestion.recordCount EQ 0>

We?re sorry?we could not find that user name in our database. Please try again.
<br /><br />
<form action=?display_question.cfm? method=?post?>
<input type=?text? name=?username? />
<input type=?submit? value=?proceed? />
</form>

<cfelse>

Please answer the following question:

<form action=?show_password.cfm? method=?post?>
<cfoutput query=?getQuestion?>
<input type=?hidden? name=?username? value=?#form.username#? />
#secretQuestion#
</cfoutput>
<br /><br />
<input type=?text? name=?secretAnswer? />
<input type=?submit? value=?proceed? />
</form>

</cfif>

</body>
</html>


show_password.cfm
<!---
finally, we query the database for the username (taken from the hidden form field on the previous page), and the secret answer (from the previous page?s form).

if the user has entered the correct answer, we can go ahead and display their password to them.
--->


<cfquery name=?checkpassword? datasource=?myDSN?>
SELECT password
FROM tbl_user
WHERE
username = <cfqueryparam value=?#form.username#? cfsqltype=?cf_sql_char?>
AND
secretAnswer = <cfqueryparam value=?#form.secretAnswer#? cfsqltype=?cf_sql_char?>
</cfquery>

<html>

<head>
<title>Request Password</title>
</head>

<body>

<!--- if a record was returned from our query? --->
<cfif checkpassword.recordCount>
<cfoutput>
Hello, #form.username#. Your password is #checkpassword.password#. Please write this down for future use.
</cfoutput>
<!--- no record was returned --->
<cfelse>
Sorry, but we were unable to verify your identity based on the information that you provided. Please <a href=?password_request.cfm?>try and enter your information again</a>.

If you feel an error has been made?please <a href=?mailto:webmaster@mysite.com?>send an e-mail to webmaster@mysite.com</a>.
</cfif>

</body>
</html>



That?s it! Depending on the level of security you want, it?s also possible to combine the two methods above, and ask a user for their e-mail address *and* the answer to a secret question before e-mailing the password.

Either way, both methods allow you to deliver instant customer service to your visitors. Something that they?re sure to appreciate, and something that will keep them coming back.

Dynamic Sorting in coldfusion

<!--- First off we need to set a default sort order so for the purposes of this
tutorial we will use fname as our default. We set this using the cfparam tag --->

<cfparam name="sortBy" default="fname"></b>

<!--- Next thing we need to do is make our call to our database using the cfquery tag --->
<!--- In this example I have used the name of my company as the datasource name you would
of course use the datasource name you have setup --->
<b> <cfquery name="dynamicSort" datasource="rez_productions">
SELECT id, fname, lname
FROM sorting
<!--- Note: the field we are sorting by is a dynamic variable which we set with our cfparam tag --->
ORDER BY #sortBy# Asc
</cfquery>

<!--- It is easier for me to give you the entire page layout for formating purposes. --->
<html>
<head>
<title>Dynamic Sorting</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<table width="500" border="1" align="center">
<tr>
<td>
<div align="center"> <!--- Note the links all reference the page we are on, yet they are passing the field name
that we want our end-user to be able to click if they want to sort by this particular field.
All three links are basically the same the only change is in the value that they are passing --->
<a href="dynamic_sort.cfm?sortBy=ID">Id</a>
</div>
</td>
<td align="left">
<div align="left">
<a href="dynamic_sort.cfm?sortBy=fname">FirstName</a>
</div>
</td>
<td>
<div align="left">
<a href="dynamic_sort.cfm?sortBy=lname">Last Name</a>
</div>
</td>
</tr>
<!--- Now we do our output. It is important to place our cfoutput tag in the proper place
so that we can dynamically generate the needed rows for the amount of data we are displaying.
Because we do not know how many rows we need we place the cfoutput tag before the opening <tr> --->
<cfoutput query="dynamicSort">
<tr>
<td><div align="center">#dynamicSort.id#</div></td>
<td>#dynamicSort.fname#</td>
<td>#dynamicSort.lname#</td>
</tr>
<!--- Note that the closing cfoutput tag is placed after the closing </tr> tag this is part of
dynamically generating rows --->
</cfoutput>
</table>
</body>
</html>


________________________________________
Thats pretty well it for basic dynamic sorting. Here is the MySql Database I used to create
this tutorial.

CREATE TABLE sorting (
id int(10) unsigned NOT NULL auto_increment,
fname varchar(255) NOT NULL,
lname varchar(255) NOT NULL,
PRIMARY KEY (id)
);

#
# Dumping data for table 'sorting'
#

INSERT INTO sorting VALUES ( '1', 'Bugs', 'Bunny');
INSERT INTO sorting VALUES ( '2', 'Road', 'Runner');
INSERT INTO sorting VALUES ( '3', 'Daffy', 'Duck');

Display random images each time a page loads or is refreshed in coldfusion

An easy way to keep the look of your site fresh is to display a different image each time the page is refreshed or loaded. Accomplishing this is a very simple task.
Say you want your header image to be the random image. First create a directory for the header images in your image directory.
ex - images/header/
Let's say we're going to swap between 4 images that are stored in our images/header/ folder. They are named 1.jpg , 2.jpg , 3.jpg , and 4.jpg
On your header cfm page you'll need two things.
First a <cfparam> statement like the following: <cfparam name="imageswap" default="#randrange(1, 4)#">
... name it whatever you want. The randrange() is the key here. Change the 4 to whatever number of images you want to swap between.
Next, an if statement:


<cfif imageswap is "1">
<img src="images/header/1.jpg" width="539" height="119" border="0">
<cfelseif imageswap is "2">
<img src="images/header/2.jpg" width="539" height="119" border="0">
<cfelseif imageswap is "3">
<img src="images/header/3.jpg" width="539" height="119" border="0">
<cfelseif imageswap is "4">
<img src="images/header/4.jpg" width="539" height="119" border="0">
</cfif>
</b>
Or you can do this:
<b><cfoutput>
<img src="images/header/#imageswap#.jpg" width="539" height="119" border="0">
</cfoutput>


That's it, they'll load randomly. You can do this with an unlimited number of images. Enjoy!

Changing site color scheme in coldfusion

I found it wasn?t to difficult to give users the ability to select a color scheme for their site. This is done by using the application.cfm to hold the variables to be used throughout the pages.

This is really easy to set up for basic functionality, you may want to add some additional error checking and security if you wanted to use this on a full blown website. But for now I'll just stick to the basics to get you started.

This page will use four CFM pages and one database.
• application.cfm
• page1.cfm
• color_maint.cfm
• color_maint_action.cfm
• database.mdb
First thing first, Lets set up a database.
Create a new database or add a table to an existing one. Save the table as "ColorScheme" and create an ODBC Connection to your DB.

Here are the fields:
Fieldname Value
---------------------
Color_ID 1
PageColor blue
The next thing to do is create the application.cfm. It's in here that we will define all Color Scheme variables to be used throughout the site.
application.cfm
============================
<!--- Checking for the user defined color scheme --->


<CFQUERY NAME="GetPageColor" DATASOURCE="MyDSN">
SELECT PageColor
FROM ColorScheme
</CFQUERY>



<!--- Begin checking for color scheme --->

<CFIF GetPageColor.ColorScheme IS "blue">
<CFSCRIPT>
BG_CLR = "##FFFFFF"; // Sets the color of the page background to white
TBL_CLR1 = "##000099"; // Sets table colors to dark blue
TBL_CLR2 = "##99CCFF"; // Sets table color to light blue
</CFSCRIPT>
<CFELSEIF GetPageColor.ColorScheme IS "green">
<CFSCRIPT>
BG_CLR = "##FFFFFF"; // Sets the color of the page background to white
TBL_CLR1 = "##339900"; // Sets table colors to dark green
TBL_CLR2 = "##99CC33"; // Sets table color to light green
</CFSCRIPT>
<CFELSEIF GetPageColor.ColorScheme IS "orange">
<CFSCRIPT>
BG_CLR = "##FFFFFF"; </b>
// Sets the color of the page background to white
TBL_CLR1 = "##FF6600"; // Sets table colors to dark orange
TBL_CLR2 = "##FFCC00"; // Sets table color to light orange
</CFSCRIPT>
</CFIF>

==========================
Next we need to set up page1.cfm to use the color schemes in the application.cfm.
NOTE THE COLOR VALUES ARE INCLUDED DYNAMICLY FROM THE APPLICATION.CFM
page1.cfm
==========================

<html>
<head>
<title>Color Scheme</title>
</head>

<body>
<table width="500" height="200" border="0" cellpadding="0" cellspacing="0">
<tr>
<CFOUTPUT><td bgcolor="#TBL_CLR1#"></CFOUTPUT>
<table width="500" height="200" border="0"cellpadding="5" cellspacing="1">
<tr>
<CFOUTPUT><td height="10" bgcolor="#TBL_CLR2#"></CFOUTPUT><strong>Page header goes here</strong></td>
</tr>
<tr>
<CFOUTPUT><td valign="top" bgcolor="#BG_CLR#"></CFOUTPUT>Additional page stuff goes here.<br>
<a href="color_maint.cfm">Click here</a> to change color scheme</td>
</tr>
<tr>
<td height="10"></td>
</tr>
</table></td>
</tr>
</table>

</body>
</html>

========================
Now we need a page that we can administer the color scheme from. I'll call it color_maint.cfm
In this page we will build out a select box for the color schemes.

Note: the hidden fields. The first one has a value of "1" and is used in the color_maint_action.cfm to determine what record needs to be updated. The second hidden field is the Opperation to be preformed. in this case it's "u" for update.

color_maint.cfm
=========================

<html>
<head>
<title>Color Maint</title>
</head>

<body>
<form name="form1" method="post" action="color_maint_action.cfm">
<input type="hidden" name="Color_ID" value="1">
<input type="hidden" name="op" value="u">

<p>Select the color scheme for your site:
<select name="ColorScheme" id="ColorScheme">
<option value="blue" selected>Blue</option>
<option value="green">Green</option>
<option value="orange">Orange</option>
</select>
<input type="submit" name="Submit" value="Update Scheme">
</p>
</form>
</body>
</html>

=========================
The last part is the actual processing of the data, and updating of the database.

In This Page the first thing it does is check if the "op" value exists, if it does not. it sends the user back to some specified page. In this case, page1.cfm

If the user submited the form it will contain the FORM.op value of "u" and will continue to process the page.
the cfupdate code will automaticly compare values with the database und update the values for Color_ID and ColorScheme

Then It will print to the screen some sort of confirmation. In this case a thank you message with a link back to page1.cfm. Once you go back to page1.cfm you will notice the new colors scheme of the tables.

color_maint_action.cfm
==========================

<html>
<head>
<title>Color Maint Action</title>
</head>

<CFIF NOT IsDefined ("FORM.op")>
<CFLOCATION URL="page1.cfm">
</CFIF>

<CFIF FORM.op IS "u">
<CFUPDATE DATASOURCE="MyDSN" TABLENAME="ColorScheme" FORMFIELDS="Color_ID, ColorScheme">

<B>THANK YOU</B><BR>
Color Scheme Updated! To view the changes, <a href="page1.cfm">Click Here</a>.

<CFELSE>
<B>Sorry</B><BR> An Error Occured.

</CFIF>

</body>
</html>

=========================
Now surf to page1.cfm and take note of the color, then go through the color changing process, and return to page1.cfm and you will new see the difference.

That's it.

cfscript in coldfusion

An Introduction to CFSCRIPT

We all know and love ColdFusion for its easy to use tag-based syntax. So why is there even a cfscript-style syntax? Well, there are a couple of reasons:
• some CFers are already proficient in other langauges, and may feel more comfortable writing program events in a more 'traditional' method.
• some people think that cfscript style syntax is easier to read (more straightforward).
• cfscript exectues faster than a comparable block of tag-based code (i've heard this is even more true in MX).
So what does all of this mean to you? Do you have to use cfscript? Absolutely not. But given the advanatges mentioned above (as well as the ability to more easily write User-Defined Functions in CF 5 and above), you may want to check out cfscript to see what it can do for you.


'Rules' of CFSCRIPT
• Place cfscript code within <cfscript></cfscript> tags.
• No ColdFusion tags can be used in cfscript blocks. Only ColdFusion functions.
• All lines must be terminated with a semi-colon (;).
• While CFSCRIPT shares many characteristics with other scripting languages such as JavaScript, it is still ColdFusion, which means ColdFusion rules/syntax still apply:
o Arrays start at position 1 (as opposed to 0)
o Use the EQ, NEQ, LT, GT (etc) comparison operators (as opposed to =, !=, <, >, etc)
o The ampersand (&) is the concatenation character (as opposed to the plus (+) character).
o CFSCRIPT is case-insensitive...but I always recommend trying to watch your cases in order to promote good programming habits

CFSCRIPT Syntax

Ok...that's all well and good. But what does it LOOK like? Fair enough. Let's start very simple. Setting a variable.

<cfscript>
myName = 'Charlie';
</cfscript>

Not so terrible, eh? :) You can even use CFSCRIPT to output your values:


<cfscript>
myName = 'Charlie';
writeOutput('my name is ' & myName);
</cfscript>


Excellent. You are well on your way :)

How about looping? Is there looping in CFSCRIPT? You bet your bippy there is ($5 to anyone who can tell me what a bippy is, by the way...i've always wondered).


Looping in CFSCRIPT


1. <cfscript>
2. myList = 'George,Paul,John,Ringo'; // creates the variable myList, which holds 4 names
3. for (i = 1; i LTE listLen(myList); i = i+1) {
4. writeOutput(listGetAt(myList, i) & "<br>");
5. }
6. </cfscript>


Let's go over this line by line, shall we?
(audience responds in unison, 'we shall')
Great.
1. Opening our
<cfscript>

block
2. create a variable called myList. Populate with 4 names (George,Paul,John,Ringo). You'll also notice the comment (the // and the text after it). This is a standard single-line script comment (similar in 'regular' CFML to <!--- comment --->). You can also do a multi-line comment, such as:
/*
This is a multi-line comment.
anything within the slash/asterisk - asterisk/slash will be ignored by the CF Server
*/
3. Here's where we get just a little funky. This line is essentially the same as <cfloop from="1" to="#listLen(myList)#"index="i">, otherwise known as a 'for' loop. It's comprised of 3 parts...let's break 'em down to make this easier to decipher:
• i = 0 -- Straightforward enough. Sets a variable i equal to 0.
• i LTE listLen(myList) -- Says to continue the loop while i is less than or equal to (LTE) the length of our 'myList' list (which contains 4 elements...so the loop will iterate 4 times).
• i = i+1 -- Increment i by 1 for each iteration (in other scripting languages, you may have seen this as i++...unfortunately, cfscript does not support this notation).
Notice also, how each 'part' is separated by a semi-colon (;). Notice also the open curly-brace ({) at the end of the line. The code that will execute for each iteration of the loop is enclosed in curly braces (we close our curly brace in line 5).
4. Here's our output. As we did in our first example, we use cfscript's writeOutput() function. Nested within that function, is a straightforward listGetAt() function...with a <br> concatenated at the end, so we get 4 lines of output after our looping is finished. Again, notice that we end the line with a semi-colon (;).
5. We're now done with our code inside of the loop, so we close our curly brace.
6. Close our cfscript block and we're done!


Conditionals in CFSCRIPT

You may also want to look at how CFSCRIPT handles conditionals...otherwise known as <cfif><cfelseif><cfelse></cfif>.

Let's take a very basic example...We're going to generate a random number between 1 and 100...and determined if it's in the first quarter (between 1 and 25), second quarter (between 26 and 50), third quarter (between 51 and 75), or fourth quarter (between 76 and 100).


1. <cfscript>
2. myRandomNumber = randRange(1,100);
3. if (myRandomNumber GTE 1 AND myRandomNumber LTE 25) {
4. writeOutput(myRandomNumber & ' is in the first quarter');
5. } else if (myRandomNumber GTE 26 AND myRandomNumber LTE 50) {
6. writeOutput(myRandomNumber & ' is in the second quarter');
7. } else if (myRandomNumber GTE 51 AND myRandomNumber LTE 76) {
8. writeOutput(myRandomNumber & ' is in the third quarter');
9. } else {
10. writeOutput(myRandomNumber & ' is in the fourth quarter');
11. }
12. </cfscript>




...and the obligatory breakdown :)
1. Opening our <cfscript> block
2. Using ColdFusion's randRange() function, we generate a random number between 1 and 100...assinging that value to the variable myRandomNumber.
3. Our first condition. Checks to see if the value of myRandomNumber is between 1 and 25 (inclusive). This uses standard ColdFusion comparsion operators GTE and LTE for 'greater-than-or-equal-to' and 'less-than-or-equal-to'. We end the line with a curly brace...as with our loop example above, any code within the curly braces will appear if this condition is met (curly braces are not mandatory if there is only one line of code to execute in the condition...however, I include them here to show syntactically correct structure).
4. This is code that will execute if the condition in line 3 (above) is met. A simple writeOutput() (which you're familiar with by now) showing the actual value of the variable myRandomNumber, and concatenated with a string literal to show that the number is in quarter one.
5. If the previous condition is not met, we specify another condition (checking for the second quarter, or values between 26 and 50 (inclusive)). The logic is the same as in the first condition. The difference to note is the else if. This is different than ColdFusion's tag-based <cfelse>, which is one word.
6. The code to execute if the condition in line 5 (above) is met. Same as line 4.
7. See line 5 :)
8. See line 6 :)
9. Our final condition. We can use a simple else as opposed to the else if. If none of the previous 3 conditions are met, this is the only one left...as such, we do not have to specify 'if myRandomNumber GTE 76 AND myRandomNumber LTE 100', as it is implicit.
10. See line 6 :)
11. Close our one open curly brace.
12. Close our cfscript block and we're done!


That's about all for this lesson. There's much more that you can do with CFSCRIPT that I did not cover here. In addition to FOR loops, you can do CONDITIONAL loops and DO WHILE loops. For conditional processing, you can also use SWITCH/CASE statements instead of (or in addition to) the conditional example above.

Saturday, September 13, 2008

Banning SPAN in coldfusion

Banning the spam
Internet spam is on the rise and more importantly spammers are targeting your site's comment forms.

They are looking for the trackback urls to fool search engines into ranking their website higher in the search results.

When this started to happen to me, I wanted to sent out emails to the offenders demanding that they stop.

Unfortunatly the spam is being generated by bots and programs not some pimple faced kid behind a keyboard.

Banning IP addresses is not enough and rarely works since intelligent spammers hide their true identity anyway.

Next approach...

Banning Keywords used by the offending sites. Thats where this tutorial comes in.

<!--- DEFINE BANNED WORDS LIST --->
<cfset BannedWordsList = "poker,casino,roulette,tournament,backgammon,vegas,gambling,baccarat,vigorish">

<!--- SET NAUGHTY POSTER VALUE TO 0 --->
<cfset naughty = 0>

<!--- LOOP OVER FORM FIELDS AND CHECK ALL FIELDS FOR BANNED WORDS SET NAUGHTY POSTER TO 1 IF BANNED WORDS WERE FOUND PERIOD --->

<cfloop index="thefield" list="#form.fieldnames#">
<cfif ListFindNoCase(BannedWordsList, Evaluate(TheField), ",")>
<cfset naughty = 1>
</cfif>
</cfloop>

<!--- IF BANNED WORDS WERE FOUND GIVE AN ERROR AND ABORT PROCESSING --->
<cfif naughty EQ 1>
<h1>ERROR</h1>
<p>You have entered a keyword that has now been banned from this site.</p>
<p>please <a href="javascript:history.go(-1);">Go back</a> and correct obvious words.</p>
<cfabort>
</cfif>

Adding form results to a file (not database) in coldfusion

How to Add Information to a File
This is a very simple yet very powerful tool to have while using ColdFusion. It comes in very handy when you want to record information but do not want to have to set up a DSN.
What this coding does is simply add results of a form (or any information) to a specified file.
I will first describe use of this file in adding information from a form to the file.
This requires 3 files for use with a form (2 always mandatory).
This is the actual code that adds the information to the file:
Put this code in a .cfm file (logcode.cfm here):

<cffile action="append" file="log.cfm" output="#form.name# | #form.email# | #remote_addr#"addnewline="Yes">

This is the code you need on the form in a separate .cfm file at any part of your website:

<form action="logcode.cfm" method="post">
Name: <input type="text" name="name">
E-Mail: <input type="text" name="email">
<input type="submit" value="Submit">
</form>

Last, you need to create the file the log will be in, name it "log.cfm" or whatever you choose so long as it corresponds to what is in the first file. Leave this file blank, as information will be written to it through the form.
Everytime someone inputs that information in you form, it will be automatically added to log.cfm.
I've found this script serves a great part simply as a visit tracker.
All you have to do is use the same code as above and put it anywhere on a page. You can get rid of the form results fields and just have it log the IP address of the visitor, the time of the visit, or any other informational gathering code.

<cffile action="append" file="log.cfm" output="#remote_addr#| DateFormat(now(), 'mmmm dd, yyyy')# #TimeFormat(Now(), 'hh:mm:ss tt')#" addnewline="Yes">
This code will log the page visitor's IP address, the date, and the time of their visit. It makes a very simple way to track usage to your site.
This code comes in great in any page or form. I like using it for user posted comments so I can easily see everything that has been submitted.
Tip: in the "output" field, use table formatting to create a very professional and easy to follow list.

verity search in coldfusion

Verity Search

If your site has a lot of content, text files, or even Excel spreadsheets, you may want to consider using the Verity Search Collection in ColdFusion. Verity Collections allow you to index your site and create a ?map? if you will, of your files. Even the contents of your doc files, PDF?s, and spreadsheets. What will really amaze you is how little it takes to set up and create.

First of all you need access to the CF administrator, or you need to have the server administrator configure the server to index your site. If you run your own server then this will be a snap.

==========================
PART ONE - Configuring the server
==========================

Open the ColdFusion administration page and log in. On the Left hand side under ?Datasources? is a link labeled ?Verity Collections? Click the link.

VERITY COLLECTIONS
This is the page you will no be on. In the first section create a NAME for your collection. This can be any name that you wish to use. I will call it ?boxcar? for now.

The PATH field is for the location you would like to store the collection file. It is not to be confused with the location of the files you want index. Leave it at the default setting unless you have reason to change it.

Next Click the button ?Create Collection?

INDEX VERITY COLLECTIONS
The field for file extensions has a few default file types already in place, however you may want to add other file types. Here is a list of files that are common that you might use. Just add the appropriate extension to the list.
ASCII Text
HTML
Lotus
Rich Text Format
Microsoft word
PDF
PowerPoint
Excel

DIRECTORY PATH is the physical location of the files on your server. IE C:\www\my_site

The RECURSIVE INDEX SUB DIRECTORY check box may be checked if you want the index to include files beneath the selected directory.

Last but not least, the RETURN URL. This is the actual path for your HTTP files.
IE. http://my_server/my_site/
It?s important to get the URL correct as this is used to create the links in your search results.

Now click Submit, your server will now index your site.

=============================
PART TWO ? Creating the search forms
=============================
Search_form.cfm
-------------------------------------
<html>
<head>
<title>Search this site</title>
</head>

<body>
<strong>What would you like to search for? </strong>
<form name="form1" method="post" action="verity_search_results.cfm">
<p>
<input name="criteria" type="text" id="criteria">
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>



-------------------------------
search_results.cfm
-------------------------------
<!--- Define a search name and specify the COLLECTION name used in the CF Admin.--->
<CFSEARCH NAME="search_boxcar"
COLLECTION="boxcar"
CRITERIA="#FORM.criteria#">

<html>
<head>
<title>Search Results</title>
</head>

<body>
<h3>Your search results </h3>

<!--- Output search results complete with score --->
<CFOUTPUT QUERY="search_boxcar">
<a href="#URL#">#Title#</a><br>
Score: #Score#<p>
</CFOUTPUT>

</body>
</html>

The key here is the CFSEARCH tag. It is the easiest search ever and no SQL involved. However, if you want to add an SQL statement you can do more with it. Like search you database or your query.
For part two of this tutorial we will be keeping the search form that was created earlier in part one. We will also need to add an update page to update our collection with the db info. Lastly we will be modifying the results page just a bit.

Just to recap here is the search form once more:
<html>
<head>
<title>Search this site</title>
</head>

<body>
<strong>What would you like to search for? </strong>
<form name="form1" method="post" action="verity_search_results.cfm">
<p>
<input name="criteria" type="text" id="criteria">
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>

Now, we want to the ability to update our collection as our site grows so, what we need to do is create an update collection page. Ill call this verity_update.cfm

Here Is what I did:

<html>
<head>
<title>Update Verity Collection</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<cfquery name="get_db_info" datasource="#dsn#">
select *
from YourTable
</cfquery>

<cfindex query="get_db_info" <!--- Specify the query from above. --->
collection="YourCollection" <!--- Specify What Collection to Update. --->
action="update" <!--- Actions include: update, delete, refresh, or purge. --->
type="custom" <!--- If action is update or delete "custom" type is required. --->
key="SomeFieldname" <!--- Key is usually set to your Key Fieldname. It will be referenced later. --->
title="AnotherFieldname" <!--- The Title will appear in the list of verity results. --->
Custom1="CustomFieldname" <!--- You may add a custom1 and custom2 field if additional information is needed. --->
body="Fields, To, Be, Indexed"> <!--- Body to be indexed, sepertaed by comas. --->

Your Collection has been updated.
</body>
</html>

Lastly we need to make the modifications to the results page.

<html>
<head>
<title>Verity Search Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<!--- Use CFSEARCH Tag with collection information here --->
<cfsearch name="YourSearchName"
collection="YourCollection"
criteria="#form.criteria#">

<!--- Begin displaying results of your serch --->
<strong>Your Results</strong>



<!--- Here I'll demonstrate How to use verity to display different types of data --->
<!--- By checking the results to see if the page is indexed or if the data is from the db I can switch modes here. --->
<cfoutput query="YourSearchName">
<cfif URL IS "">
<p><a href="item_details.cfm?Item_ID=#key#">#title#</a><br>
Score: #score#</p>
<cfelse>
<p><a href="#URL#">#title#</a><br>
Score: #score#</p>
</cfif>
</cfoutput>
</body>
</html>