> Anyway this whole client side validation thing is just a pain, save
> yourself
> a lot of headache and only perform server side validation, I feel there is
> a
> time
> for JS and not.

While you always want to do server-side validation (never rely solely on
client-side validation,) qForms makes just doing client-side validation a
breeze.

Here's the code I'd need to write to require some fields. Place the follow
code block on any page where you want to use qForms:

        <!--// load the qForm JavaScript API //-->
        <SCRIPT SRC="/lib/qforms.js"></SCRIPT>
        <SCRIPT LANGUAGE="JavaScript">
        <!--//
        // set the path to the qForms directory
        qFormAPI.setLibraryPath("/lib/");
        // this loads all the default libraries
        qFormAPI.include("*");
        //-->
        </SCRIPT>

The above code is cut-n-paste. You don't need to write anything. Save it as
a Snippet in CFStudio/HomeSite (or whatever editor you use) and just include
it on the pages you need. (Or, have a variable you can set to include it in
a site-wide header file.)

Now, here's the code you'd have to write. This code should appear either
after the ending form tag, or you can fire it off in function during the
window's onLoad event handler.

<script language="JavaScript">
<!--//
// "frmExample" is the value of the "name" attribute
// of your <form> tag
oForm = new qForm("frmExample");

// this would require the "name", "email" and "phone"
// form fields. It doesn't matter if these fields are
// a text box, password, hidden, select box, checkbox
// or radio button--it's all good
oForm.required("name, email, phone");
}
//-->
</script>

You could now apply more specific validation, by adding some lines after the
oForm variable declaration:

// would make sure the "email" field appears to be a valid e-mail
// address
oForm.email.validateEmail();

// make sure the phone number field is in the format
// "(xxx) xxx-xxxx". If the field is not required, and
// the field is blank, no validation occurs.
oForm.phone.validateFormat("phone1");


-Dan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
                                

Reply via email to