PHP Classes

File: syntacticValidationFramework.js

Recommend this page to a friend!
  Classes of Richard Munroe   SQL Data   syntacticValidationFramework.js   Download  
File: syntacticValidationFramework.js
Role: Auxiliary data
Content type: text/plain
Description: JavaScript framework for validating generated form fields.
Class: SQL Data
Generate classes to store objects in SQL databases
Author: By
Last change: Reorganize the includes and switch the license over to the local standard.
Date: 18 years ago
Size: 3,336 bytes
 

Contents

Class file image Download
// // @author Dick Munroe <munroe@csworks.com> // @copyright copyright (c) Dick Munroe, 2004-2006, All rights reserved. // @license http://www.csworks.com/publications/ModifiedNetBSD.html // // The Syntactic Validation error framework. // // This is the version that was brought from the Florida Democratic Party. We // had a bunch, but this one was the rough draft version. // // It relies on the DOM model to be available so the the form definition // from which the validation framework is called provides the information // necessary to do the validation. The form is properly generated by // buildForm.php // // $Author: munroe $ // $Date: 2006/03/14 13:49:33 $ // // Edit History: // // Dick Munroe munroe@csworks.com 03-May-2005 // Break out the validation framework into a seperate JavaScript // file so that it can simply be included by the form processor, // followed by any form specific validation routines. // // Dick Munroe munroe@csworks.com 14-Mar-2006 // Change licensing, reorganize includes. // var theErrorData ; function clearErrorReport(what) { var theErrorRow = document.getElementById("errorRow") ; // // Get rid of any prior error display before proceeding. // if (theErrorRow.firstChild != null) { theErrorRow.removeChild(theErrorRow.firstChild) ; } theErrorData = document.createElement("td") ; var dataTable = theErrorRow ; // // Since the error row must be inside a table, head up and get // the number of columns in the table so that the error display // does not get constrained by the size of the table data cell. // while ((dataTable = dataTable.parentNode)["tagName"] != "TABLE") { } theErrorData.colSpan = dataTable.getAttribute("cols") ; } function insertErrorData(text) { theErrorData.appendChild(document.createTextNode(text)) ; theErrorData.appendChild(document.createElement("br")) ; } function isEmpty(str) { // Check whether string is empty. for (var intLoop = 0; intLoop < str.length; intLoop++) if (" " != str.charAt(intLoop)) return false; return true; } function isRequired(what) { var required = what.getAttribute("required") ; if (required == undefined) { return true ; } if (required != "") { if (isEmpty(what.value)) { insertErrorData(required) ; return false ; } } return true ; } function validate(what) { clearErrorReport() ; var theErrorRow = document.getElementById("errorRow") ; var theResult = true ; // // Skip through all the element and validate them. // for (var i = 0; i < what.elements.length; i++) { var theValidateString = what.elements[i].getAttribute("validate") ; if ((theValidateString != null) && (theValidateString !="")) { var theValidateFunction ; theValidateFunction = new Function("what", theValidateString) ; theResult &= theValidateFunction(what.elements[i]) ; } } if (theResult) { return true ; } else { theErrorData.appendChild(document.createElement("br")) ; theErrorRow.appendChild(theErrorData) ; return false ; } }