/*~ worxvalidate.js.php .---------------------------------------------------------------------------. | Software: Worx Form Validator/Submit | | Version: 0.1 | | Contact: codeworxtech@users.sourceforge.net | | Info: http://phpmailer.codeworxtech.com | | ------------------------------------------------------------------------- | | Author: Andy Prevost andy.prevost@worxteam.com (admin) | | Copyright (c) 2002-2008, Andy Prevost. All Rights Reserved. | | ------------------------------------------------------------------------- | | License: Distributed under the Lesser General Public License (LGPL) | | http://www.gnu.org/copyleft/lesser.html | | This program is distributed in the hope that it will be useful - WITHOUT | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | | FITNESS FOR A PARTICULAR PURPOSE. | | ------------------------------------------------------------------------- | | We offer a number of paid services: | | - Web Hosting on highly optimized fast and secure servers | | - Technology Consulting | | - Oursourcing (highly qualified programmers and graphic designers) | '---------------------------------------------------------------------------' Last updated: November 27 2008 21:08 EST /** * Worx Form Validator/Submit * @package Worx Form Validator/Submit * @author Andy Prevost * @copyright 2008 Andy Prevost * * Worx Form Validator/Submit is a multi-purpose javascript tool. In order * of processing, the features are (when the submit button is pressed): * - checks the status of the class tag and if set to "required" makes * the field required. If empty, the field will gain focus and form * is not submitted * - disables the Submit and Reset button (prevents multiple submissions) * - submits the form * * Worx Form Validator/Submit is as unobtrusive as possible. When combined * with CSS, required fields are set with a unique background color. When * required fields are empty, the form is not submitted (and no data loss * occurs) and the empty field is set to focus. * * Please review the enclosed article for a complete explanation of the * strategy behind this script. */ //var mailer = "arbitrary.php"; // comment this after your complete your testing var mailer = "_lib/nunlos.php"; // uncomment this after you complete your testing /* FUNCTIONS */ function validateForm(wrxForm) { // you can insert any form validation here var allPassed = true; var allTags = document.getElementsByTagName("*"); for (var i=0; i -1) { thisTag.focus(); if (thisTag.nodeName == "INPUT") { thisTag.select(); } return false; } return true; function validBasedOnClass(thisClass) { var classBack = ""; switch(thisClass) { case "": case "invalid": break; case "required": if ( allPassed && ( thisTag.value == "" || thisTag.value == "Type your message here" ) ) { classBack = "invalid "; } classBack += thisClass; break; default: classBack += thisClass; } return classBack; } } // END } function disableForm(wrxForm) { if (document.all || document.getElementById) { for (i = 0; i < wrxForm.length; i++) { var tempobj = wrxForm.elements[i]; if (tempobj.type.toLowerCase() == 'submit' || tempobj.type.toLowerCase() == 'reset') { tempobj.disabled = true; } } } } function submitForm(wrxForm) { disableForm(wrxForm); // disable submit and reset buttons wrxForm.action = mailer; // reset the action of the form wrxForm.submit(); // submit the form return true; // return true status } function initForms() { for (var i=0; i< document.forms.length; i++) { document.forms[i].onsubmit = function() { return validateForm(this); } } } function focusCursor() { for (var i = 0; i < document.forms.length; ++i) { var f = document.forms[i]; for (var j = 0; j < f.elements.length; ++j) { if (f.elements[j].type == 'text' || f.elements[j].type == 'textarea') { f.elements[j].focus(); return; } } } } /* * LOAD WITH THE SCRIPT CALL - DO NOT REMOVE THIS * * This next code snippet is what displays the form, sets up the form to use * the checks for required fields. Once the required fields tests are met, * this will disable the submit and reset buttons, and submit the form. */ window.onload = function() { document.getElementById("wrxFormDiv").style.display="block"; initForms(); focusCursor(); }