This is a simple but effective way of getting rid of HTML tags and make the HTML string into plain text to output:
#REReplace(htmlStr,”<[^>]*>”,”",”All”)#
Example HTML: <h1>Title</h1><p>My content<p>
Example Output after: Title My content
This is a simple but effective way of getting rid of HTML tags and make the HTML string into plain text to output:
#REReplace(htmlStr,”<[^>]*>”,”",”All”)#
Example HTML: <h1>Title</h1><p>My content<p>
Example Output after: Title My content
One of the main things all developers come to in applications is pagination and the best way we found to do this is by Raymond Camden which covers how to create next and previous buttons for your content using the URL variable.
As we have extended what Raymond Camden has done we will go through all the code again to make sure you get the full picture.
First part is to get our data, which most of the time will be a database or as the second data example shows a queryNew which is a way of creating data in a query format without the need of a database query.
<cfquery name=”data” datasource=”data_dsn”>SELECT *</cfquery>
OR
<cfset data = queryNew(“id,name,age,active”,”integer,varchar,integer,bit”)>
<cfloop index=”x” from=”1″ to=”22″>
<cfset queryAddRow(data)><cfset querySetCell(data,”id”,x)>
<cfset querySetCell(data,”name”,”User #x#”)>
<cfset querySetCell(data,”age”,randRange(20,90))><cfset querySetCell(data,”active”,false)>
</cfloop>
Next we want to set the number of records per page we would like to show, for this example code we are using 10:
<cfset perpage = 10>
Now we create the code for the URL variables which counts the records in the data we have got from our database / query. We also set the default of the variable URL.start to 1 as we want to start from the first record and not 0.
<cfparam name=”url.start” default=”1″>
<cfif not isNumeric(url.start) or url.start lt 1 or url.start gt data.recordCount or round(url.start) neq url.start>
<cfset url.start = 1>
</cfif>
The output of the data, you will notice on our <cfoutput> tag we have startrow & maxrows which sets what records are displayed.
<cfoutput query=”data” startrow=”#url.start#” maxrows=”#perpage#”>
#currentrow#) #name#<br />
</cfoutput>
And now this is when the code that Raymond Camden created changes a little to add in a new feature, page numbering. We first have a previous link which has an if statement around it to see if its a link or not and enable the <a> tag or have no link on it. This can be done different ways but to keep with Raymond Camden’s code we will leave it as it is. Now the new part you can see within the commented area (<!— Start Page Number —> CODE <!— End Page Number —>) we set 2 variables one for a page count as we need to have a number of pages that will be listed. The next one is page link, this is to fit in with the rest of the code and add the number that will need to be added within the link to view the numbered page. Next is a loop to go through the number of pages with the link and a small bit of VERY simple maths to add up the next page through the loop.
<p align=”center”>
[
<cfif url.start gt 1>
<cfset link = cgi.script_name & "?start=" & (url.start - perpage)>
<cfoutput><a href="#link#">Previous Page</a></cfoutput>
<cfelse>
Previous Page
</cfif>
/
<!--- Start Page Number --->
<cfset pageCount = 1>
<cfset pageLink = 1><cfset totalPages = Ceiling(rs_getReports.recordCount / perpage)>
<cfloop index="c" from="1" to="#totalPages#">
<cfoutput>
<a href="?start=#pageLink#">#pageCount#</a>
</cfoutput>
<cfset pageCount = pageCount + 1>
<cfset pageLink = pageLink + perpage>
</cfloop>
<!--- End Page Number --->
/
<cfif (url.start + perpage - 1) lt rs_getReports.recordCount>
<cfset link = cgi.script_name & "?start=" & (url.start + perpage)>
<cfoutput><a href="#link#">Next Page</a></cfoutput>
<cfelse>
Next Page
</cfif>
]
</p>
Thats it, you will now have something that looks like this:
![]()
Base code taken from Raymond Camden’s coldfusionjedi.com :
http://www.coldfusionjedi.com/index.cfm/2006/4/24/ColdFusion-and-Pagination
After 3 months of development first staging of the Polar CMS script has been released to our testers / designers to start playing with.
Process of our testing
- Add page elements to change
- Use the WYSIWYG editor
- Apply code to front end site to test speeds
The Coldfusion dateformat works in the same sort of fashion as the ASP.NET and the PHP date time function. As our team mainly works in Coldfusion we can expand alot more on this function that ASP.NET / PHP.
The code: (Use this code within a <cfoutput></cfoutput> tag)
#DateFormat(Now(), "YYYY")#
About the code:
As you can see all we start with DateFormat which states will want to have a date format (You can use TimeFormat to work with times). Next we are getting the current date with the Now() and then we have the formatting of the date, as we only want the year we are using ‘YYYY’ (Displays: 2009) or you can use ‘YY’ (Displays: 09)
Enjoy!
Many of our clients have been asking about detecting if a user is using a blackberry or iPhone etc to view their website and redirect to a mobile version of their websites. Well we have put together a little bit of code to do this:
Code example:
<cfif findNoCase('blackberry', CGI.HTTP_USER_AGENT)>
<cflocation url="http://blackberry.yourdomain.com" addtoken="no">
<cfelseif findNoCase('iphone', CGI.HTTP_USER_AGENT)>
<cflocation url="http://iphone.yourdomain.com" addtoken="no">
<cfelseif CGI.HTTP_ACCEPT CONTAINS "text/vnd.wap.wml">
<cflocation url="http://wap.yourdomain.com" addtoken="no">
</cfif>
Hope you enjoy this code snippet.
vBulletin use a different way of HASHING the password for users (vb_user table), we have been able to allow a Coldfusion page to retrieve the username and password to allow you to use the vBulletin database on your website for account.
With this you will get an idea on adding new records into the database from non-vbulletin pages.
First thing to do is access the Coldfusion administrator and add the vBulletin MySQL database as a datasource (DSN).
When you have done this to test that you can connect to the database add this to your CF page:
<cfquery name=”rs_users” datasource=”vb_forum”>
SELECT userid, username, password, email, salt
FROM vb_user
</cfquery>
<cfdump var=”#rs_users#”>
This will run a cfdump of the content of the table, there are many more columns that just “userid, username, password, email, salt” but these are the important ones for now.
Now for the code that will make your application work with vBulletin’s database:
<cfif IsDefined(‘FORM.username’) AND FORM.username NEQ ”>
<cfquery name=”rs_user” datasource=”vb_forum”>
SELECT username, password, salt
FROM vb_user
WHERE username = ‘#FORM.username#’
</cfquery><cfset vbPassword = #lCase(HASH(lCase(HASH(FORM.password, “MD5″)) & #rs_user.salt#, “MD5″))#>
<cfquery name=”rs_finduser” datasource=”vb_forum”>
SELECT userid, username, password, email
FROM vb_user
WHERE username = ‘#FORM.username#’
AND password = ‘#vbPassword#’
</cfquery><cfdump var=”#rs_finduser#”>
</cfif>
<form name=”login” method=”post”>
Username: <input name=”username” /><br />
Password: <input name=”password” /><br />
<input name=”submit” type=”submit” />
</form>
From this you can now set your SESSIONS and start using data from the vBulletin database to integrate your website better.
Hope you find this useful.
When working with some of our clients on windows servers we have noticed Coldfusion has some problems when working with images for cfdocument. The Coldfusion shows a 60 second time out error.
We found out that it was due to the image location as Coldfusion appears to pull all the files onto is main application so full fold paths are required.
Normally using:
<img src=”/images/image.jpg”/>
Instead of using the HTTP you need to use the file system path:
<img src=”file:///C:\drivefolder\wwwroot\sitename\images\image.jpg“/>
This corrects the issues with Coldfusion 7+ (Problem still in CF 8).
| <CFIF CGI.HTTP_ACCEPT CONTAINS “text/vnd.wap.wml”> <CFLOCATION URL=”/wap/index.cfm”> </CFIF> |
NOTE: This is untested but I have seen this code used on live projects.
We are going to look into using the ColdFusion components known as CFC’s and how easy they can make your web applications.
Some benefits of using CFCs
The tutorial
Our first step is to create a database & datasource, you can find all SQL & source files with the ZIP file attached to this thread (You may need to login to access).