/*~ 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 = "PHPMailer/_lib/phpmailer-fe.php"; // uncomment this after you complete your testing /* FUNCTIONS */ function validateForm(wrxForm) { // you can insert any form validation here var whatform=wrxForm; var allPassed = true; var allTags = wrxForm.elements; // PAF var emailpat = /^[\w-]+(\.[\w-]+)*@([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})$/i; var teststr = wrxForm.email.value; if ( !teststr.match(emailpat) ) { alert ( "Invalid Email Address" ); allPassed = false; wrxForm.email.select(); } //end PAF added validation 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 (var 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 //added by PAF var whatID=document.getElementById(wrxForm.parentNode.id); var procelement=getElementsByClass("procimgdiv",whatID,'div'); procelement[0].style.visibility = "visible"; procelement[0].style.display = "block"; procelement=getElementsByClass("procimg",whatID,'img'); setTimeout('procelement[0].src = "/calculator/processing.gif"', 200); //window.location.hash = "#processing"; // end PAF wrxForm.submit(); // submit the form return true; // return true status } 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. */ //Additional by PAF //PAF for default text function clearDefaultText(e) { var target = window.event ? window.event.srcElement : e ? e.target : null; if (!target) return; if (target.value == target.defaultText) { target.value = ''; } } function replaceDefaultText(e) { var target = window.event ? window.event.srcElement : e ? e.target : null; if (!target) return; if (target.value == '' && target.defaultText) { target.value = target.defaultText; } } function addEvent(element, eventType, lamdaFunction, useCapture) { if (element.addEventListener) { element.addEventListener(eventType, lamdaFunction, useCapture); return true; } else if (element.attachEvent) { var r = element.attachEvent('on' + eventType, lamdaFunction); return r; } else { return false; } } // searchClass = what you are looking for // node = id // tagname = limit to type eg input function getElementsByClass(searchClass,node,tag) { var classElements = new Array(); if ( node == null ) node = document; if ( tag == null ) tag = '*'; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); var i=0,j=0; for (i = 0, j = 0; i < elsLen; i++) { if ( pattern.test(els[i].className) ) { classElements[j] = els[i]; j++; } } return classElements; } function initdefaultevents() { //get all input fields and set event handlers to clear and replace default text var formInputs = document.getElementsByTagName('input'); for (var i = 0; i < formInputs.length; i++) { var theInput = formInputs[i]; if (theInput.type == 'text' && theInput.className.match(/\brequired\b/) ) { // Add event handlers addEvent(theInput, 'focus', clearDefaultText, false); addEvent(theInput, 'blur', replaceDefaultText, false); // Save the current value if (theInput.value != '') { theInput.defaultText = theInput.value; } } } // display forms on page for (var i = 1; i <=9; i++) { var theInput = "wrxFormDiv"+i; var gotWorx=document.getElementById(theInput); if (gotWorx != null) { gotWorx.style.display="block"; } } // set onsubmit function for forms for (var i=0; i< document.forms.length; i++) { if (document.forms[i].id.match(/\btheForm[0-9]/) ) { document.forms[i].onsubmit = function(i) { return validateForm(this); } } } }