PDA

View Full Version : Trouble with form


ransom
10-01-2008, 05:49 PM
I am having trouble with a form. can anyone help.
ransom

var req:URLRequest;
var emailLoader:URLLoader;


var email_to_send:String = "sales@mortechmfg.com";// ...
var contact_form_subject_title:String = "Request a catalog";
var contact_form_title:String = "Website Request";


send_mc.mouseChildren = false;
send_mc.buttonMode = true;
send_mc.addEventListener(MouseEvent.MOUSE_OVER,sen dOnMouseOver);
send_mc.addEventListener(MouseEvent.MOUSE_OUT,send OnMouseOut);
send_mc.addEventListener(MouseEvent.MOUSE_DOWN,sen dOnMouseDown);


tel_txt.restrict = "0-9.|/";
name_txt.tabIndex = 0;
title_txt.tabIndex = 1;
org_txt.tabIndex = 2;
street_txt.tabIndex = 3;
city_txt.tabIndex = 4;
state_txt.tabIndex = 5;
zip_txt.tabIndex = 6;
country_txt.tabIndex = 7;
tel_txt.tabIndex = 8;
fax_txt.tabIndex = 9;
email_txt.tabIndex = 10;
msg_txt.tabIndex = 11;
clearFields();
setAnimationOnFocus();
function clearFields():void {
name_txt.text = "";
title_txt.text = "";
org_txt.text = "";
street_txt.text = "";
city_txt.text = "";
state_txt.text = "";
zip_txt.text = "";
country_txt.text = "";
tel_txt.text = "";
fax_txt.text = "";
email_txt.text = "";
msg_txt.text = "";
}


function setAnimationOnFocus():void {
name_txt.addEventListener(FocusEvent.FOCUS_IN, textOnFocusIn);
title_txt.addEventListener(FocusEvent.FOCUS_IN, textOnFocusIn);
org_txt.addEventListener(FocusEvent.FOCUS_IN, textOnFocusIn);
street_txt.addEventListener(FocusEvent.FOCUS_IN, textOnFocusIn);
city_txt.addEventListener(FocusEvent.FOCUS_IN, textOnFocusIn);
state_txt.addEventListener(FocusEvent.FOCUS_IN, textOnFocusIn);
zip_txt.addEventListener(FocusEvent.FOCUS_OUT, textOnFocusOut);
country_txt.addEventListener(FocusEvent.FOCUS_OUT, textOnFocusOut);
tel_txt.addEventListener(FocusEvent.FOCUS_OUT, textOnFocusOut);
fax_txt.addEventListener(FocusEvent.FOCUS_OUT, textOnFocusOut);
email_txt.addEventListener(FocusEvent.FOCUS_IN, textOnFocusIn);
msg_txt.addEventListener(FocusEvent.FOCUS_OUT, textOnFocusOut);
}


function textOnFocusIn(e:FocusEvent):void {
if (e.target == name_txt) {
bk1.gotoAndPlay("s1");
} else if (e.target == title_txt) {
bk2.gotoAndPlay("s1");
} else if (e.target == org_txt) {
bk3.gotoAndPlay("s1");
} else if (e.target == street_txt) {
bk4.gotoAndPlay("s1");
} else if (e.target == city_txt) {
bk5.gotoAndPlay("s1");
} else if (e.target == state_txt) {
bk6.gotoAndPlay("s1");
} else if (e.target == zip_txt) {
bk7.gotoAndPlay("s1");
} else if (e.target == country_txt) {
bk8.gotoAndPlay("s1");
} else if (e.target == tel_txt) {
bk9.gotoAndPlay("s1");
} else if (e.target == fax_txt) {
bk10.gotoAndPlay("s1");
} else if (e.target == email_txt) {
bk11.gotoAndPlay("s1");
} else if (e.target == msg_txt) {
bk12.gotoAndPlay("s1");
}
}

function textOnFocusOut(e:FocusEvent):void {
if (e.target == name_txt) {
bk1.gotoAndPlay("s2");
} else if (e.target == title_txt) {
bk2.gotoAndPlay("s2");
} else if (e.target == org_txt) {
bk3.gotoAndPlay("s2");
} else if (e.target == street_txt) {
bk4.gotoAndPlay("s2");
} else if (e.target == city_txt) {
bk5.gotoAndPlay("s2");
} else if (e.target == state_txt) {
bk6.gotoAndPlay("s2");
} else if (e.target == zip_txt) {
bk7.gotoAndPlay("s2");
} else if (e.target == country_txt) {
bk8.gotoAndPlay("s2");
} else if (e.target == tel_txt) {
bk9.gotoAndPlay("s2");
} else if (e.target == fax_txt) {
bk10.gotoAndPlay("s2");
} else if (e.target == email_txt) {
bk11.gotoAndPlay("s2");
} else if (e.target == msg_txt) {
bk12.gotoAndPlay("s2");
}
}



function validateFields():Boolean {
info_mc.gotoAndStop(1);
var send_mesg:Boolean = true;
if (name_txt.text == "" || name_txt.text == " " ) {
//trace("INSERT NAME");
stage.focus = name_txt;
name1.gotoAndStop(2);
send_mesg = false;
} else if (title_txt.text == "" || title_txt.text == " ") {
//trace("INSERT TITLE");
stage.focus = title_txt;
title.gotoAndStop(2);
name1.gotoAndStop(1);
send_mesg = false;
} else if (org_txt.text == "" || org_txt.text == " ") {
//trace("INSERT ORGANIZATION");
stage.focus = org_txt;
org.gotoAndStop(2);
title.gotoAndStop(1);
name1.gotoAndStop(1);
send_mesg = false;
} else if (street_txt.text == "" || street_txt.text == " ") {
//trace("INSERT STREET");
stage.focus = street_txt;
street.gotoAndStop(2);
org.gotoAndStop(1);
title.gotoAndStop(1);
name1.gotoAndStop(1);
send_mesg = false;
} else if (city_txt.text == "" || city_txt.text == " ") {
//trace("INSERT CITY");
stage.focus = city_txt;
city.gotoAndStop(2);
street.gotoAndStop(1);
org.gotoAndStop(1);
title.gotoAndStop(1);
name1.gotoAndStop(1);
send_mesg = false;
} else if (state_txt.text == "" || state_txt.text == " ") {
//trace("INSERT STATE");
stage.focus = STATE_txt;
state.gotoAndStop(2);
city.gotoAndStop(1);
street.gotoAndStop(1);
org.gotoAndStop(1);
title.gotoAndStop(1);
name1.gotoAndStop(1);
send_mesg = false;
} else if (zip_txt.text == "" || zip_txt.text == " ") {
//trace("INSERT ZIP");
stage.focus = zip_txt;
zip.gotoAndStop(2);
state.gotoAndStop(1);
city.gotoAndStop(1);
street.gotoAndStop(1);
org.gotoAndStop(1);
title.gotoAndStop(1);
name1.gotoAndStop(1);
send_mesg = false;
} else if (country_txt.text == "" || country_txt.text == " ") {
//trace("INSERT COUNTRY");
stage.focus = country_txt;
county.gotoAndStop(2);
zip.gotoAndStop(1);
state.gotoAndStop(1);
city.gotoAndStop(1);
street.gotoAndStop(1);
org.gotoAndStop(1);
title.gotoAndStop(1);
name1.gotoAndStop(1);
send_mesg = false;
} else if (tel_txt.text == "" || tel_txt.text == " ") {
//trace("INSERT PHONE");
stage.focus = tel_txt;
name2.gotoAndStop(2);
county.gotoAndStop(1);
zip.gotoAndStop(1);
state.gotoAndStop(1);
city.gotoAndStop(1);
street.gotoAndStop(1);
org.gotoAndStop(1);
title.gotoAndStop(1);
name1.gotoAndStop(1);
send_mesg = false;
} else if (fax_txt.text == "" || fax_txt.text == " ") {
//trace("INSERT FAX");
stage.focus = fax_txt;
fax.gotoAndStop(2);
name2.gotoAndStop(1);
county.gotoAndStop(1);
zip.gotoAndStop(1);
state.gotoAndStop(1);
city.gotoAndStop(1);
street.gotoAndStop(1);
org.gotoAndStop(1);
title.gotoAndStop(1);
name1.gotoAndStop(1);
send_mesg = false;
} else if (validateEmail(email_txt.text) == false) {
//trace("INVALID EMAIL");
stage.focus = email_txt;
email.gotoAndStop(2);
fax.gotoAndStop(1);
name2.gotoAndStop(1);
county.gotoAndStop(1);
zip.gotoAndStop(1);
state.gotoAndStop(1);
city.gotoAndStop(1);
street.gotoAndStop(1);
org.gotoAndStop(1);
title.gotoAndStop(1);
name1.gotoAndStop(1);
send_mesg = false;
} else if (msg_txt.text == "" || msg_txt.text == " ") {
//trace("INSERT MESSAGE");
stage.focus = msg_txt;
email.gotoAndStop(1);
fax.gotoAndStop(1);
name2.gotoAndStop(1);
county.gotoAndStop(1);
zip.gotoAndStop(1);
state.gotoAndStop(1);
city.gotoAndStop(1);
street.gotoAndStop(1);
org.gotoAndStop(1);
title.gotoAndStop(1);
name1.gotoAndStop(1);
message.gotoAndStop(2);
send_mesg = false;
}
if (send_mesg) {
email.gotoAndStop(1);
name2.gotoAndStop(1);
name1.gotoAndStop(1);
message.gotoAndStop(1);
}
return send_mesg;
}
function validateEmail(str:String):Boolean {
var pattern:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
if (pattern.test(str)) {
return true;
} else {
return false;
}
}
function sendOnMouseOver(e:MouseEvent):void {
e.target.gotoAndPlay("s1");
}
function sendOnMouseOut(e:MouseEvent):void {
e.target.gotoAndPlay("s2");
}


function sendOnMouseDown(e:MouseEvent):void {
if (validateFields()) {
sendMessage();
}
}

function sendMessage():void {
info_mc.gotoAndStop(4);
send_mc.mouseChildren = false;
send_mc.mouseEnabled = false;
send_mc.alpha = .5;
req = new URLRequest("send_message.php");
req.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.email_to_send = email_to_send;
variables.contact_form_subject_title = contact_form_subject_title;
variables.contact_form_title = contact_form_title;
variables.name_txt = name_txt.text;
variables.title_txt = title_txt.text;
variables.org_txt = org_txt.text;
variables.street_txt = street_txt.text;
variables.city_txt = city_txt.text;
variables.state_txt = state_txt.text;
variables.zip_txt = zip_txt.text;
variables.country_txt = country_txt.text;
variables.tel_txt = tel_txt.text;
variables.fax_txt = fax_txt.text;
variables.email_txt = email_txt.text;
variables.msg_txt = msg_txt.text;
req.data = variables;
emailLoader = new URLLoader();
emailLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
emailLoader.addEventListener(Event.COMPLETE,emailO nComplete);
emailLoader.addEventListener(IOErrorEvent.IO_ERROR ,onErr);
try {
emailLoader.load(req);
} catch (e:Error) {
clearFields();
}
}

function emailOnComplete(e:Event):void {
hadleError(e.target.data.sent);
//trace(e.target.data);
}

function hadleError(mes:String):void {
if (mes == "OK") {
//trace("MESSAGE SENT");
send_mc.mouseEnabled = true;
send_mc.alpha = 1;
info_mc.gotoAndStop(2);
clearFields();
} else {
//trace("MESSAGE NOT SENT");
clearFields();
send_mc.mouseEnabled = true;
send_mc.alpha = 1;
info_mc.gotoAndStop(3);
}
}

function onErr(e:IOErrorEvent):void {
clearFields();
//trace(e + " ERROR");
send_mc.mouseEnabled = true;
send_mc.alpha = 1;
info_mc.gotoAndStop(3);
}

mcgrailm
10-01-2008, 07:23 PM
thats allot of code that could possible condensed aside from that could you tell us what the problem your having is also could you post the fla file for us ?