Click to See Complete Forum and Search --> : help customising form validation script


idiotbear
10-15-2003, 08:00 AM
hi

I've been customising Dreamweaver's form validation script, but there's one thing I still want to do which I can't get to behave properly.

The function which I call looks like this:


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[i]);
if (val) { nm=val.id; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@' || '.');
if (p<1 || p==(val.length-1)) errors+='- "'+nm+'" must contain a valid e-mail address.\n\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- "'+nm+'" must contain a number.\n\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\n';
} } } else if (test.charAt(0) == 'R') errors += '- "'+nm+'" is a required field.\n\n'; }
} if (errors) alert('The information you entered is invalid for \n the following reasons:\n\n'+errors);
document.MM_returnValue = (errors == '');
}


This is called from the onSubmit event like so:

onSubmit=" MM_validateForm('First Name','','R','Surname','','R','E-mail','','RisEmail','Number of Documents','','R'); return document.MM_returnValue; "

Now, what I want to do is to put a confirm box into the onSubmit, asking the user if they're sure they want to proceed before running the MM_validateForm() function. I'd normally do this like:

function confirmProceed()
{
confMsg=Confirm("Are you sure you want to proceed? \n \n You won't be able to edit this information later.")
if (confMsg == true)
{return true}
else
{return false}
}

Then I'd call it in onSubmit like

onSubmit="return confirmProceed"

Now, how can I build that function into the MM_validateForm() function so that you get the confirm first, then if OK is clicked, the MM_validateForm() function fires. If cancel is clicked, the form is not submitted.

I can't get my head round Dreamweaver's code!

Cheers

Rob

pyro
10-15-2003, 08:22 AM
Cross-posted and answered in the JavaScript section: http://forums.webdeveloper.com/showthread.php?s=&threadid=19333