Better way to validate this form?

Hi again,

Ive made a form in flash. Simple enough, collects data in a LoadVars obj and this is sent to a PHP script. Im trying to do all the validation within flash, my conditional statement(s) below works, however its pretty long. Does anyone have any suggestions to compact it? Ie make it more effcient?

Just to explain the script:
Firstly, as you can see im using a boolean var (submit) which keeps repeatedly being set depending whether the particular condition is true or not. Finally the last statment checks the value of the submit boolean var to see whether all fields have been correctly

Secondly I have movieclips called attention(n)_mc, which simply appear beside fields which have been entered incorrectly


function processApp(component){
	if (name == undefined){
		submit=false;
		attention1_mc._visible=true;
	}else{
		submit=true;
		attention1_mc._visible=false;
	}
	if (surname== undefined){
		submit=false;
		attention2_mc._visible=true;
	}else{
		submit=true;
		attention2_mc._visible=false;
	}
	if (occupation == undefined){
		submit=false;
		attention3_mc._visible=true;
	}else{
		submit=true;
		attention3_mc._visible=false;
	}
	if (company == undefined){
		submit=false;
		attention4_mc._visible=true;
	}else{
		submit=true;
		attention4_mc._visible=false;
	}
	if(email1==undefined || email2==undefined || email1 != email2 || email1.indexOf("@") != -1){
		submit=false;
		attention5_mc._visible = attention6_mc._visible = true;
	}else{
		submit=true;
		attention5_mc._visible = attention6_mc._visible = false;
	}
	if(submit==true){
		component.setEnabled=false;
		status_txt.htmlText = "Verfying all details entered correctly, please wait...";
		trace("details entered");
		$senddata.name=name;
		$senddata.surname=surname;
		$senddata.street=street;
		$senddata.suburb=suburb;
		$senddata.postcode=postcode;
		$senddata.state=state;
		$senddata.occupation=occupation;
		$senddata.company=company;
		$senddata.email1=email1;
		status_txt.htmlText = "Registering you now, please wait...";
		$senddata.sendAndLoad("newRegister.php",$recievedata,"POST");
		//loadVariablesNum("newlogin.php", 0, "POST");
	}else{
		this._parent.attachMovie("attentionNoticeClip", "attentionNotice_mc", 100, {_x:Stage.width/2,_y:Stage.height/2});
		attentionNotice_mc._visible=true;
	}
};

guess not… :frowning:

Thanks Tviman, I have siince changed it…Im just having trouble optimising the validation of my form. Essentially I have little arrows which are visible beside incorrect fields …Here’s what I have now:

Can anyone see a better way of doing this?


function processApp(component){
	component.enabled=false;//disable submission button to stop accidental multiple submissions
	required1_mc._visible = required2_mc._visible = required3_mc._visible = required4_mc._visible = required5_mc._visible = required6_mc._visible = required7_mc._visible = required8_mc._visible = required9_mc._visible = required10_mc._visible = required11_mc._visible = required12_mc._visible = false;
	//status_txt.htmlText = "Processing your application, please wait...";
	if((first_name==undefined || first_name.trim()=="") || (last_name==undefined || last_name.trim()=="") || (street==undefined || street.trim()=="") || (suburb==undefined || suburb.trim()=="") || (postcode==undefined || postcode.trim()=="") || (state==undefined || state.trim()=="") || (country==undefined || country.trim()=="") || (area_code==undefined || area_code.trim()=="") ||(business_ph==undefined || business_ph.trim()=="") || (title==undefined || title.trim()=="") || (company==undefined || company.trim()=="") || (email_address1==undefined || email_address1.trim()=="") || (email_address2==undefined || email_address2.trim()=="")){
		this.attachMovie("alertCmp", "alert_cmp", 100, {title:"Alert: Please check form",message:"You did not submit the following required information!",x:Stage.width/2,y:Stage.height/2});
		
		if (first_name==undefined || first_name.trim()==""){
			trace("no first name");
			required1_mc._visible=true;
		}
		if (last_name==undefined){
			required2_mc._visible=true;
		}
		if(street==undefined){
			required3_mc._visible=true;
		}
		if(suburb==undefined){
			required4_mc._visible=true;
		}
		if(postcode==undefined){
			required5_mc._visible=true;
		}
		if(state==undefined){
			required6_mc._visible=true;
		}
		if (country==undefined){
			required7_mc._visible=true;
		}
		if (area_code==undefined){
			required8_mc._visible=true;
		}
		if (business_ph==undefined){
			required8_mc._visible=true;
		}e
		if(title==undefined){
			required9_mc._visible=true;
		}
		if(company==undefined){
			required10_mc._visible=true;
		}
		if(email_address1==undefined){
			required11_mc._visible=true;
		}
		if(email_address2==undefined){
			required12_mc._visible=true;
		}
		component.enabled=true;
	}
	
	else if(email_address1.indexOf("@") == -1 || email_address2.indexOf("@") == -1){
		this.attachMovie("alertCmp", "alert_cmp", 100, {title:"Alert: Please check form", message:"Please enter your email address in the correct format",x:Stage.width/2,y:Stage.height/2});
		if(email_address1.indexOf("@") == -1){
			required11_mc._visible=true;
		}
		if(email_address2.indexOf("@") == -1){
			required12_mc._visible=true;
		}
		component.enabled=true;
	}
	else if(email_address1 != email_address2){
		this.attachMovie("alertCmp", "alert_cmp", 100, {title: "Alert: Please check form", message:"Email mismatch, make sure you have entered your email address correctly",x:Stage.width/2,y:Stage.height/2});
		component.enabled=true;
	}
	else{
		
		//status_txt.htmlText = "Thankyou for your patience, sending your application now...";
		$sendData.first_name=first_name.trim();
		$sendData.last_name=last_name.trim();
		$sendData.street=street.trim();
		$sendData.suburb=suburb.trim();
		$sendData.postcode=postcode.trim();
		$sendData.state=state.trim();
		$sendData.country=country.trim();
		$sendData.title=title.trim();
		$sendData.company=company.trim();
		$sendData.area_code=area_code.trim();
		$sendData.business_ph=business_ph.trim();
		$sendData.mobile_ph=mobile_ph.trim();
		$sendData.email_address=email_address1.trim();
		$sendData.sendAndLoad("php/user_reg.php",$recieveData,"POST");
		
	}
};