PDA

View Full Version : validation on forms



ssaville24
06-19-2002, 06:48 PM
> Please help I'm need to developing websites.
>
> How can I validate a group of fields in a form that only need to be
> required if one other field is required.
>
> I have some fields that are required and then other dependent
> fields. I need to be able to require a few other fields that are
> dependent on if another field has been populated.
>
> here is my code...
>
> 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.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') {
>
> 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 (val<min || max<val) 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 == '');
>
> }
>
>
> ------------------------
>
> <input type="submit" name="Submit" value="Submit"
> onfiltered="MM_validateForm
>
('Dealer_Company_Name','','R','Dealer_Contact_Name','','R','DealerTele
>
phone','','R','Dealer_Review_Mgr_Name','','R','Registered_Company_Name
> ','','R','Company_Street_Address','','R','Company_City','','R','Comp
an
>
y_State','','R','Company_Zip','','R','Company_Country','','R','Company
>
_Telephone','','R','Billing_Contact_First_Name','','R','Billing_Contac
>
t_Last_Name','','R','Billing_Contact_Phone','','R','Billing_Contact_Em
>
ail','','RisEmail','Billing_Street_Address','','R','Billing_State','',
> 'R','Billing_City','','R','Billing_Country','','R','Billing_Zip_Code
',
> '','R');return document.MM_returnValue">

whammy
06-20-2002, 03:19 AM
Hmm... it would be better if you just posted the original HTML form (without the MM_BLAH89a7hdsf89blahblahblah), and told us what form fields you want validated rather than posting that Macromedia code.

That WYSIWYG editor validation is atrocious (and hard to edit)... I would advise not using it, personally... :D

Is it possible to present a plain form (only HTML) without the horrible WYSIWYG code that we could validate using plain logic?

If not, I would personally rewrite the form...

P.S. I don't mean anything personal against you... but if this is the case then just using the HTML from the form itself and eliminating all of the "generated" javascript code would definitely be in your best interests!

:)