I have a few questions about Form field validation pop up windows. I am using Adobe Dreamweaver CS3 on a Mac running OSX 10.4.11.
1. How can I change the text in form field validation pop up windows?
For example, when an email address is entered incorrectly I get the following text in a pop up window, ''The following error(s) occurred: - email must contain an e-mail address.'' How can I change this text to read ''Email Address does not appear to be valid. Please correct.''?
2. Does the text field name have to appear as-is in an error pop up window?
For example, I get the error message below when information is not entered into a required field (account# is the name of the text field in Dreamweaver).
The following error(s) occurred:
- account# is required.
How can I remove the hyphen and capitalize Account?
Form field validation pop up windowsYou can modify the code that Dreamweaver insert to get the desired effects, but be aware that if you re-insert or modify the Form Validation behavior your changes will be overwritten and you'll have to redo them.
If you look in the head of your document, you'll see this JavaScript code (with my line numbers for reference):
1?function MM_validateForm() { //v4.0
2?if (document.getElementById){
3?var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
4?for (i=0; i%26lt;(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
5?if (val) { nm=val.name; if ((val=val.value)!='''') {
6?if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
7?if (p%26lt;1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
8?} else if (test!='R') { num = parseFloat(val);
9?if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
10?if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
11?min=test.substring(8,p); max=test.substring(p+1);
12?if (num%26lt;min || max%26lt;num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
13?} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
14?} if (errors) alert('The following error(s) occurred:\n'+errors);
15?document.MM_returnValue = (errors == '');
16?} }
The overall message - The following error(s) occurred: - appears in line 14. While you can modify this, be careful doing so. At a bar minimum, the line should read:
} if (errors) alert(errors);
That will completely remove the general message, but list all the errors.
To change the email validation message, modify line 7 to read something like:
if (p%26lt;1 || p==(val.length-1)) errors+='Email Address does not appear to be valid. Please correct.\n';
To change the required message, change line 13 to something like:
} } } else if (test.charAt(0) == 'R') errors += 'Account is required.\n'; }
Again, keep in mind that this is changing the validation routine for this page - and these form elements - only and you'll have to redo the changes if you ever re-open the Form Validation behavior on this page again.
Best - Joe
Joseph Lowery
Author, Dreamweaver CS4 Bible
No comments:
Post a Comment