cftopper.com

Javascript Validation: Don't use WITH keyword

Using the with keyword is considered bad javascript programming style
because the javascript engine has to do a lot of work to interpret what you mean.

So don't use

with( document.registrationForm )
{
if( userEmail.value.length == 0 )...

Instead use:

var f = document.registrationForm;
if( f.userEmail.value.length == 0 )...
Tags: Javascript | Tips

How to Beat Form Spam-bots

...without resorting to an annoying CAPTCHA.

Those bloody form spam bots were driving our clients crazy with hundred of bs emails arriving every day. I came up with this simple but effective method to beat these form spam-bots.

Part 1 - Duping New Bots


Warning: This method assumes needs JavaScript enabled and is thus not blah-blah compliant.

  1. Change the action of your form to "about:blank". (Remember the real action for later.) Robots indexing this will now go to "about:blank" instead of your action handler page.
  2. If your form has a JavaScript validation function, add this line just before the form is OKed or submitted:

    document.[form name].action = "[path to form handler page]"

    Otherwise just stick in something like this in the form:

    onsubmit="this.action='[Path to handler page here]'"

It's pretty simple, but since implementing this at the crew, we haven't encountered any robots smart enough to figure out that we are duping them with the about:blank. If the robots evolve, then so will we.

Part 2 - Blocking Old Bots (they're using Form Caching!)


Part 1 will prevent robots indexing your form action URL; but what about the robots who have already indexed your form and are storing the form details in their database? Here's how to block them:

  1. Add this line to your form:

    <input type="hidden" name="formSecurity" value="<cfoutput>#Hash( DateFormat( now(), "dd/mm/yyyy" ) & "YOUR_SECRET_KEY" )#</cfoutput>"/>

  2. In your handler page insert the following at the start:

    <!--- FORM SECURITY --->
    <cfif NOT isdefined( "FORM.formSecurity" ) OR ( FORM.formSecurity IS NOT Hash( DateFormat( now(), "dd/mm/yyyy" ) & "YOUR_SECRET_KEY" ) )>
        <cfabort>
    </cfif>

Tada! Your done. Welcome to zero-spam.
Alternative method: Cut the internet cable running out of Nigeria.

Prototype.js Vs AjaxRequest.js

I am considering dropping AjaxRequest (which is excellent) and switching over to prototype.js for the comments part of this site (I will be loading both the comments and comment posts via Ajax).

Shit. I search and searched and can't see if prototype.js supports easy submitting of form data via Ajax like AjaxRequest does. You see I'm a lazy developer and like my frameworks to do this sort of form serialisation grudge-work for me. Hmmm... to use AjaxRequest which has easy form submission via Ajax or to oppose and suffer the slings and arrows of prototype.js making me do it for myself. I could use both but AjaxRequest is 9K and prototype.js is 46K and I'd rather stick with one. Decisions, decisions.

Update

Ok ok, I thoroughly examined prototype.js Ajax abilities and actually posting form data is absolutely simple. And so the winner is... prototype.js.

Tags: Javascript

Prototype.js documentation?

This Prototype javascript library that everybody is talking about looks to be fantastic but where the hell is the documentation? I mean apart from the Sitepoint article and a few others theres no official documentation (or even a promise of documentation en-route)!

I've just done a big of digging and have just found that Sergio Pereira has just written "Developer Notes for Prototype.js" which is an excellent introduction to the prototype library. In his notes, I found a good overview of the main reason I am thinking about using prototype.js at the moment - it's easy-to-use but powerful Ajax framework.

I have to say I am very impressed with the Ajax.Updater class which will just shunt a bit of HTML returned from the server into place on your existing page with almost no developer effect:

var myAjax = new Ajax.Updater(
'placeholder',
url,
{
method: 'get',
parameters: pars
});

I like it!!

Tags: Javascript

About Topper on ColdFusion

Peter Coppinger aka Topper is a neurotic web monster who spends most of his chaotic life developing ColdFusion web applications when not drinking himself into a stupor and scheming his plans for world dominance.

Peter founded Digital Crew way back in 1999. Digital Crew run CFTagStore.com and have also produced lots of powerful ColdFusion tools like ProFlashUpload and CFMyAdmin.

I made this site to share my thoughts, tips and tools with fellow ColdFusion developers.

If your a ColdFusion developer, go ahead and subscribe to this site and in exchange i'll try to provide quality content to make it worth your while.
RSS Feed for Topper on ColdFusion

I'm speaking at CF-United Europe!

CFDevCon I'm going to be speaking at CFDevCon08! It's my second time speaking in front of more than 10 people so please lend your support.

The topic is:
Introducting TeamworkCMS and Site Engine - Building better websites in half the time or something like that..

Digging

My Work - Just Finished

  • modules.cit.ie
    Web-=based modules/programmes designer tool and database system for Cork institute of technology.
  • Teamwork Project Manager
    The top secret project is finally released. The project management app will rock your world - give it a go.
  • PMG
    New website for Project Management Group website.
  • Digital Warehouse Wholesale
    Added wholesale products to existing client website.
  • New Digital Crew documentation website
    New version of documentation.digital-crew.com using new InfinityCMS site engine. It's done now. Just add content.
  • PFH Company Webite
    New website/CMS/Newsletter System for prestigious Irish IT company.
  • Module Manager for CIT
    CIT is switching to module based courses. We are making an application for managing/submitting these modules. Gettig there.
  • Bons Secours Cork Hospital Intranet
    New Intranet for Bons Secours hospital in Cork. Considering turning this Intranet system into stand-alone product.
  • Revamping InfinityCMS
    I'm making major improvements to our content management solution, InfinityCMS. Making it faster, more powerful and easier to check into/out-of source control. Done but it's always going to be evolving.
  • BPC Update
    Minor functionality update for internal Pfizer Best Process Chemistry project.