| home / new / cfjsvalidate |
|
|
Web programming with Cold Fusion, or any language, almost always involves forms. Where there are forms, there must be input validation. CF supports server-side form validation, but not very efficiently. Because of this, most developers supplement their forms with client-side JavaScript validation. This article presents a script that provides automatic JavaScript validation for Cold Fusion-validated forms. Use it to get the best of Cold Fusion and JavaScript validation, without duplicating your validation logic.
Cold Fusion ValidationCold Fusion employs hidden form fields to validate the contents of user-entered data. Here is a hidden field that ensures that a text box is not empty:
<input type="hidden" name="companyName_required" VALUE="Please
provide a company name">
The name of the field determines the actual form element being validated and the type of validation required. The field's value contains the message to be displayed if validation fails. In this case, Cold Fusion will require the form element 'companyName' to contain a value. Other types of validation are supported for most kinds of available form elements. CF validation will get the job done, but it requires extra trips to the server when validation errors occur. While you can specify a validation message, it will be displayed on a rather pedestrian page, no matter how elegantly your site is designed. The user must press the Back button to return to the form to make corrections, and in some cases, this will wipe out the contents of the form. I can't think of a better way to annoy a user.
JavaScript ValidationJavaScript, on the other hand, seems well suited for validation tasks. Validation occurs on the client-side, not the server, so it is efficient. When validation errors occur, an alert box is displayed, and the user stays on the form that needs fixing, instead of going to an error page. JavaScript also has one whopper of a drawback: it can be disabled by the user. Granted, few users will do so, but since validation is the science of dealing with exceptions, if you can't achieve 100% validation, you lose the whole ball game. Next: The Best of Both Approaches This article originally appeared in the September 7, 2000 edition of the WebReference Update Newsletter. |
Comments are
welcome
Written by Joe Copley and
Solutions
Whitepapers and eBooks
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Microsoft Article: 7.0, Microsoft's Lucky Version?
Microsoft Article: Hyper-V--The Killer Feature in Windows Server 2008
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Windows Server 2008
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES
The latest from WebReference.com
Browse >
Software Engineering for Ajax - Part 2
·
How to Create an Ajax Autocomplete Text Field: Part 6
·
Software Engineering for Ajax
Sitemap · Experts · Tools · Services · Email a Colleague · Contact
FREE Newsletters >
The latest from internet.com
Oracle 10g Cloning Guide: A Small County Government Approach
·
Using File Virtualization for Disaster Recovery
·
Provider Profile: CommPartners Connect
Revised: Sept. 8, 2000
URL: http://webreference.com/new/cfjsvalidate.html