Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forms and Validation

Status
Not open for further replies.

swizzy

Technical User
Apr 2, 2004
59
US
I have created a form in Dreamweaver and the form works however a message comes up that says:

Form Error(s):

FIELD: comments -> ERROR: string cannot be empty

How do I make the "comments" field in my form NON-required?

I deleted the "required.add('comments','NOT_EMPTY');"

in my validation script and yet it STILL requires that the visitor fill in the "comments" field.

any suggestions on how to validate the "comments" field to where it is NOT necessary to fill out the comments field would be most appreciated.

TIA

Miss Swizzy
 
I suppose that would help 8^):

************************

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a.indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a;}}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a)&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<title>contact</title></head>

<body bgcolor="#333333" style="color: rgb(0, 0, 0);;" onload="MM_preloadImages('images/Buttons/images/buttonsOVER_04.jpg','images/Buttons/images/buttonsOVER_05.jpg','images/Buttons/images/buttonsOVER_08.jpg','images/Buttons/images/buttonsOVER_09.jpg','images/Buttons/images/buttonsOVER_10.jpg','/images/Buttons/images/buttonsOVER_06.jpg')">
<script> // SPECIFY ALL REQUIRED FIELDS AND // SEE validation.js for other options
required.add('What date would you like to meet with me?','ALPHANUMSPACE');
required.add('What time would you prefer to meet?','ALPHANUMSPACE');
required.add('fullname', 'NOT_EMPTY');
required.add('Your City or ZIP code','ALPHANUMSPACE');
required.add('email', 'EMAIL');
required.add('Contact number including area code','NUMERICPLUS');
required.add('Alternate phone, if any','NUMERICPLUS');
required.add('Best days and times to call?','ALPHANUMSPACE');
required.add('How did you find me?','NOT_EMPTY');
required.add('comments','NOT_EMPTY');
required.add('answer_out', 'NUMERIC');
</script>

********************

I deleted the required.add('comments','NOT_EMPTY');
but it still didn't work.

thank you for your assistance GUJUm0deL !!

Miss Swizzy
 
Are you just trying to do a simple form validation? If so why not code the actual form validation yourself. I never use the JS code that DW puts in (I don't think anyone here really does).

A custom JS validation can be very easy.

Something like:
Code:
// START: CONTACT FORM
function validateME () {
	var gM = document.FormNAME;
	var errorMSG = "";
	
	if(gM.First_Name.value == "") { errorMSG += "First Name\n"; }
	if(gM.Last_Name.value == "") { errorMSG += "Last Name\n"; }
	if(gM.Phone.value == "") { errorMSG += "Phone\n"; }
	if(gM.Email.value == "") { errorMSG += "E-mail\n"; }

	if(errorMSG != "") {
		alert("The following fields are required:\n=========================\n" + errorMSG + "=========================\n");
		return false;
	}	
}
// END: CONTACT FORM

____________________________________
Just Imagine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top